NEW YORK -- Thousands of police officers from across the U.S. packed a church and spilled onto streets outside Saturday to honour a slain New York officer as a devoted family man, aspiring chaplain and hero, though an air of unrest surrounding his ambush shooting was not completely pushed aside.

While mourners inside the church applauded politely as Mayor Bill de Blasio spoke, hundreds of officers outside turned their backs on him to protest what they see as his support for demonstrators angry over killings by police.

The rush of officers far and wide to New York for Ramos' funeral reminded some of the bond after the Sept. 11, 2001, attacks and Superstorm Sandy. Vice-President Joe Biden promised that the "incredibly diverse city can and will show the nation how to bridge any divide."

Still, tensions were evident when officers turned away from giant screens showing de Blasio, who has been harshly criticized by New York Police Department union officials as a contributor to a climate of mistrust that preceded the killings of Ramos and his partner, Wenjian Liu.

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. In online posts shortly before the attack, Brinsley referenced the killings of Michael Brown and Eric Garner, both of whom were black and unarmed, by white police officers.

Police union officials in contentious contract negotiations with the city have faulted de Blasio for showing sympathy to protesters angry over the failure to file charges against the police officers involved in the deaths of Brown in Ferguson, Missouri, and Garner in the New York borough of Staten Island.

At a hospital after the officers' slayings, the police union's president, Patrick Lynch, and others turned their backs on de Blasio. Lynch said the mayor had "blood on his hands."

Outside the church, Sgt. Myron Joseph of the suburban New Rochelle Police Department said he and fellow officers turned their backs spontaneously to "support our brothers in the NYPD."

In a statement, de Blasio's spokesman said: "The Ramos and Liu families, our police department and our city are dealing with an unconscionable tragedy. Our sole focus is unifying this city and honouring the lives of our two police officers."

The NYPD said through its public relations office that it had no comment.

In his eulogy, de Blasio said hearts citywide were broken after the Dec. 20 shootings.

"All of this city is grieving and grieving for so many reasons," de Blasio said. "But the most personal is that we've lost such a good man, and the family is in such pain."

Gov. Andrew Cuomo praised the sea of blue mourners for their professionalism at recent rallies over police conduct when protesters insulted them, and Biden spoke passionately about the effects of the officers' deaths.

"When an assassin's bullet targeted two officers, it targeted this city and it touched the soul of an entire nation," the vice-president said.

After the funeral, Lynch and de Blasio exchanged nods as they exited the church. Lynch refused to answer reporters' questions about officers turning their backs.

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.

Soon after taking office this year, de Blasio dropped the city's opposition to a judge's finding that the police department discriminated against minorities with its anti-crime stop-and-frisk tactics.

But since last week's shootings, de Blasio has stood firmly by police, calling on demonstrators to temporarily halt protests and praising the department after it arrested several men charged with threatening police.

The killings shook the city and put a halt to large-scale local protests criticizing police over the high-profile, in-custody deaths.

When the Ramos family arrived at church Saturday, the elder son -- wearing his father's NYPD jacket -- was hugged by a police officer.

Ramos, a 40-year-old married father of two, was studying to become a pastor and kept Bible study books in his locker, his commanding officer said.

Police Commissioner William Bratton said Ramos had been made honorary chaplain of the police precinct where he had worked.

Bratton said in his eulogy that Ramos and Liu would be "partners for all time."

Officer Dustin Lindaman of the Waterloo Police Department flew from Iowa to attend the funeral.

"He's one of our brothers, and when this happens, it affects everyone in law enforcement -- it absolutely affects everyone," he said.

Ramos and Liu were the first officers to die in the line of duty in New York since 2011. Funeral plans for Liu haven't yet been announced.

They have both been posthumously promoted to first-grade detective.