Hundreds of officers who attended the funeral of a slain US police officer turned their backs on Mayor Bill de Blasio as he gave a speech at a New York church.

As mourners inside the church applauded politely for the mayor on Saturday, officers outside turned their backs on him in a show of disrespect for what they see as his support for anti-police protesters.

De Blasio was speaking at the funeral of Rafael Ramos, who was shot dead along with his patrol partner Wenjian Liu in Brooklyn a week ago.

Their deaths have become a nationwide rallying point for police and supporters, beleaguered by months of street protests accusing police of racist practices.

The man who shot the officers said he was avenging the killing of unarmed black men by police.

Police union leader blames recent protests for the killing of officers in New York

Speaking of Ramos, who joined the police department relatively late in his working life after a career as a school safety officer, the mayor said: "He had a dream that he would one day be a police officer.

"He couldn't wait to put on that uniform. He believed in protecting others and those who are called to protect others are a special breed."

Vice President Joe Biden, who also attended the funeral, told mourners the double murder was felt by the whole country.

"When an assassin's bullet targeted two officers, it targeted this city. And it touched the soul of the entire nation," Biden said.

After the officers were shot to death, the gunman, Ismaaiyl Brinsley, killed himself. Police said he was troubled and had shot and wounded an ex-girlfriend in Baltimore earlier that day.

'Blood on his hands'

De Blasio has been harshly criticised by NYPD union officials as a contributor to a climate of mistrust that preceded the killings of Ramos and Liu.

Union leaders have faulted the mayor for showing sympathy to protesters angry over the failure to file charges against the police officers involved in the deaths of Michael Brown in Ferguson, Missouri, and Eric Garner in the New York borough of Staten Island.

At a hospital after the officers' slayings, the police union's president, Patrick Lynch, said the mayor had "blood on his hands".

Weeks before the shooting, Lynch had suggested officers sign a petition requesting that the mayor not attend their funerals were they to die in the line of duty.

A particular comment by the liberal mayor that triggered allegations of anti-police rhetoric was that he publicly said he had advised his biracial son to be "very careful" in dealing with the police.

Source: Agencies