Thousands of police from around the country spilled out of a church into the streets surrounding a slain New York City officer's funeral on Friday, calling for respect and understanding at a time when law enforcement is being deeply scrutinized.

Busloads of officers arrived from as far as California, Louisiana, and Chicago for Officer Brian Moore's funeral on Long Island. As a hearse carried his coffin to the cemetery, they lined up 10 and 20 deep to salute him.

"Brian's death comes at a time of great challenge" for officers nationwide, who are "increasingly bearing the brunt of loud criticism," Police Commissioner William Bratton said.

Only five months earlier, the New York Police Department mourned two other officers who were killed in an ambush by a gunman who said he wanted revenge for police killings of civilians.

"What is lost in the shouting and the rhetoric is the context of what we do," said Bratton, his voice cracking as he posthumously promoted the 25-year-old Moore to the rank of detective. "What is lost is the way we already work together, the ways we get it right. ... What is lost is that public safety is a shared responsibility."

Moore died Monday, two days after he was shot in Queens. He and his partner were in street clothes in an unmarked car and were stopping a man suspected of carrying a handgun when the suspect shot him in the head.

Moore's death came amid a national debate about policing, race and deadly force following the recent killings of unarmed black men by officers in New York; Ferguson, Missouri; North Charleston, South Carolina, and elsewhere.

Amid the outcry, New York City Officers Rafael Ramos and Wenjian Liu, were killed in their patrol car in December. The man who gunned them down had boasted online that he would kill police in revenge for the chokehold death of Eric Garner on Staten Island and the shooting of Michael Brown in Ferguson.

Liu's relatives were among the mourners at Moore's funeral, which was guarded by snipers on the roof of a nearby elementary school as a police helicopter hovered in the three-mile no-fly zone authorities imposed overhead.

Detective Omar Daza-Quiroz, 33, traveled from Oakland, California, to stand with his colleagues — and stand for law enforcement.

"Right now, it's a tough time in law enforcement," he said. "Sometimes people forget we are human and that we have lives."

Moore was the son, nephew and cousin of NYPD officers, and two other cousins serve on Long Island. Moore was so determined to follow them that he took the police entrance exam at 17 and "devoted his whole being to the job," Mayor Bill de Blasio said.

After having to take a few weeks off for medical leave recently, Moore "counted the minutes" until he could return to work, and made a gun arrest his second day back — only a few days before he himself was shot, de Blasio said.

At Ramos' and Liu's funerals, hundreds of officers turned their backs to the mayor in a searing sign of disrespect. Police union leaders had said de Blasio had helped foster an anti-NYPD sentiment by allowing protesters to march through the city's streets after a grand jury decided not to indict an officer in Garner's death.

An uneasy truce between de Blasio and the police eventually settled in after some police union infighting, a public backlash to a NYPD job slowdown and a series of City Hall investments in the police department. There has been no similar sign of tensions in the wake of Moore's death, and no backs were turned on de Blasio Friday.

De Blasio's "words are measured and careful to know that there's support, and that's important," said Patrolmen's Benevolent Association President Patrick Lynch, who once said de Blasio had "blood on his hands" after Liu's and Ramos' deaths.

Moore had been on the force for only a handful of years, but he had already built up a record of more than 150 arrests and had earned meritorious service medals. His posthumous promotion — common practice when New York officers die in the line of duty — will provide additional death benefits for his family.

Dedicated to his work, Moore also "knew, no matter what, how to put a smile on your face," his brother Steven Velasquez, 25, said after the funeral. "That's the one thing everyone loved about him."

The suspect in Moore's killing, Demetrius Blackwell, faces charges including murder, attempted murder and other crimes. He is being held without bail and has not entered a plea. His attorney has denied the charges.