The NYPD’s newest cops were on their best behavior Monday as Mayor de Blasio welcomed them to the force — even as their supporters belted out a round of boos and cries of “traitor.”

“Generations of NYPD officers come forward and, one after another, have done better and better and better and made this city safer and safer. And now the baton is being passed to you to continue that progress,” de Blasio told the 884 officers at the graduation ceremony in Madison Square Garden.

“And the people of this city need it. So you’ll be hitting the ground running later this week, out patrolling and protecting the people of this city.”

Hizzoner was jeered by a few spectators as he took the podium, and some turned their backs in a protest similar to those he has faced since the murders of two NYPD cops in their squad car.

The boos also came with a few cries of “traitor” and heckling during his brief remarks.

“Let’s be honest about the realities of our society. You will confront all the problems that plague our society — problems that you didn’t create,” de Blasio said.

“You did!” someone then yelled, prompting laughter and applause.

There was a silence when de Blasio told the grads they were “joining a winning team” and cited this year’s nearly 5 percent drop in crime, which he called “an achievement for the ages.”

De Blasio is trying to mend fences with his police officers.

Many have felt a lack of support from the mayor since the chokehold death of Eric Garner on Staten Island. Afterward, de Blasio angered cops by saying he has taught his son about potential dangers posed by the police.

The tensions boiled over when Officers Rafael Ramos and Wenjian Liu were shot dead by a gunman who wrote that he was seeking to avenge the deaths of Garner and Michael Brown, who was killed by a cop in Ferguson, Mo.

NYPD Chief Chaplain Rabbi Alvin Kass led a moment of silence for Ramos and Liu before Monday’s swearing-in ceremony.

Police Commissioner Bill Bratton told the crowd he wanted to talk to the new officers “cop to cop,” adding, “In my heart, in my soul, I always will be a cop. And I use that term proudly.”

“We need you to keep this city safe,” Bratton said. “We’re in a very difficult time at this time, in this country, in this city, in this department.”

The new cops were born in 51 different countries and speak a total of 59 languages in addition to English, the NYPD said.

They bring the department’s uniformed membership to 34,423.

Class members include Kevin Lynch, whose father, Pat, is president of the Patrolmen’s Benevolent Association and one of the mayor’s harshest critics.

Pat Lynch has accused de Blasio of throwing cops “under the bus” with his response to Garner’s death. After Ramos and Liu’s murders, he said the “blood on the hands starts at City Hall.”

After the ceremony — which featured a video with actor James Earl Jones intoning, “We are the NYPD” — several parents of new cops blasted de Blasio for not supporting the department.

“When you are mayor of the biggest city, you have to watch what you say,” said Linda Difinzio, 52, of Queens, whose son is one of the new officers.

“[The police] felt betrayed. The mayor needs to redeem himself.”

Cindy Williams of Bethpage, LI, said her son had graduated into “a dangerous job with so much hate going on toward the Police Department.”

“I don’t have much respect for the mayor,” she added.

Additional reporting by Yoav Gonen, Shawn Cohenand Antonio Antenucci