Tens of thousands of police and other mourners filled a New York City church and nearby streets for the funeral of one of two police officers shot dead by a man who said he was avenging the killing of unarmed black men by police.

The deaths of Rafael Ramos and his patrol partner Wenjian Liu, who were singled out for their uniforms, have become a nationwide rallying point for police and supporters, beleaguered by months of street protests accusing police of racist practices.

Addressing Ramos's widow Maritza, US vice-president Joe Biden said: "Your husband, and his partner, they were a part of New York's finest, and that's not an idle phrase."

He added: "I believe that this great police force of this incredibly diverse city can and will show the nation how to bridge any divide. You've done it before and you will do it again."

Police department chief ­spokesman Stephen Davis said Ramos's funeral might prove the largest in the history of the force. Streets outside the church were filled for blocks with neat, quiet crowds of officers in blue uniform, including force delegations from Boston, Atlanta, St Louis and New Orleans.

The service at Christ Tabernacle Church in Ramos's Queens neighbourhood also brought together Mayor Bill de Blasio and the police officers and union leaders for the first time in public since an extraordinary confrontation a week ago at the hospital where the two officers were pronounced dead.

Hours after Ramos, 40, and Liu, 32, were killed while sitting in their parked patrol car in ­Brooklyn on December 20, police officers, in an unusually pointed display of disgust, turned their backs on the mayor as he arrived at the hospital.

Marking the most toxic relations in decades between a New York City mayor and his police ­department, union leaders, enraged by his expressions of support for the protests against police practices, said de Blasio had "blood on his hands".

Yesterday, as the mayor began speaking at the funeral, thousands of police officers in at least one part of the crowd outside all turned their backs to a large ­projection screen.

"He had a dream that he would one day be a police officer," de Blasio said of Ramos, who joined the police department relatively late in his working life after a career as a school safety 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."

New York Governor Andrew Cuomo spoke about how Liu and Ramos represented the diversity of the city's police department, which he said had officers of more than 50 nationalities speaking 64 languages.

The officers' killer, Ismaaiyl ­Brinsley, 28, fatally shot himself soon after the attack, and had earlier the same day shot and wounded his former girlfriend in Baltimore, Maryland.

Brinsley, who was black, had ­written online that he wanted to kill police officers to avenge the deaths of Eric Garner and Michael Brown - unarmed black men killed by white policemen in New York and Missouri respectively.

Their deaths and the decisions not to prosecute the officers responsible ignited nationwide protests, renewing a debate about race in America that has drawn in President Barack Obama.