Eight days after two NYPD officers were shot dead in an ambush attack, Mayor Bill de Blasio on Monday commended the 884 graduates of this year's New York City police academy class for answering a "noble calling" and making a "heroic choice."

"You will stare down the danger, you will keep the peace," de Blasio told the graduates in dress blues at Madison Square Garden. "You will confront all the problems that plague our society. Problems that you didn't create -- "

A member of the audience interrupted by shouting at the mayor, "You created them!" and was met with some laughs and clapping at his disruption. De Blasio went on to cite poverty and mental illness as the problems.

The crowd bowed their heads in a moment of silence in memory of Officers Rafael Ramos and Weijian Liu, gunned down Dec. 21 as they sat in their patrol car in Brooklyn by a man who wielded anti-police sentiments. Relations between de Blasio and the police have been strained in part because police union leaders have condemned him as unsupportive to the force.

De Blasio was booed by a handful of people in the stands when he took the stage, and a few audience members in plainclothes stood with their backs to him during his speech.

The mayor had faced a more blatant protest at Ramos' funeral Saturday in Queens when hundreds of officers turned their backs to him as he delivered the eulogy.

De Blasio did not react visibly to the smatterings of protest Monday.

Mayoral spokeswoman Marti Adams in an email message to reporters pointed out that former mayors Michael Bloomberg and Rudy Giuliani had also been booed at NYPD graduation ceremonies.

In his speech, de Blasio emphasized the city's responsibility to protect its police officers just as the cops protect the public. He highlighted a "worthy" $400 million investment in training for the NYPD and $160 million in new tablets and smartphones.

"You will be continuously supported and trained," de Blasio said.

NYPD Commissioner William J. Bratton, addressing the graduates afterward, also said ongoing training will help keep officers safe. He spoke to the graduates "cop to cop" about the challenges of the job and the difficulties of losing a colleague.

The graduating class' valedictorian, Officer James Fuchs, who shook de Blasio's hand after receiving the mayor's award for the highest overall average, spoke about the honor of becoming a police officer.

He concluded on a cautionary note to his comrades: "Be safe, be alert, and never let your guard down."

The graduates concluded the ceremony with a salute to Ramos and Liu, whose pictures were projected from the Jumbotron at the Garden.