An emotional funeral service for one of the two New York police officers gunned down in an attack last week took a divisive turn when several hundred cops turned their backs on New York Mayor Bill de Blasio while he spoke during the event.

Thousands of mourners gathered at Christ Tabernacle Church in the Glendale neighborhood of Queens for the wake of Rafael Ramos, one of two NYPD officers fatally shot while on duty in Brooklyn on December 20. The two officers, Ramos and Wenjian Liu, were ambushed while sitting in their patrol car. Their assailant, Ismaaiyl Brinsley, allegedly sought revenge for the deaths of Eric Garner and Michael Brown, unarmed black men whose deaths at the hands of police sparked nationwide protests in recent months.

The leader of New York's largest police union has claimed de Blaiso's comments in the weeks before the deadly attack contributed to the anti-police sentiment that motivated Brinsley, who killed himself after shooting Ramos and Liu.

Hours after Ramos and Liu were pronounced dead last week, Patrolmen's Benevolent Association president Pat Lynch blamed the killings on "those that incited violence on the street under the guise of protests that tried to tear down what New York City police officers did every day."

Lynch said the mayor and officials at New York City Hall had "blood on their hands."

Several police officers turned their backs on de Blasio in a sign of disrespect when he spoke at a press conference on the night the officers were killed, and many more repeated the gesture again Saturday. The Associated Press reported that "hundreds" of cops watching Ramos' funeral on giant TV screens outside the church turned away when de Blasio spoke.

Officers turning backs to Mayor De Blasio. Other officers from around the country doing the same. — Lawrence Crook (@LawrenceCNN)December 27, 2014

Hundreds of cops turn their backs on screen showing — Tony Aiello (@AielloTV)December 27, 2014

1000s of police officers on Myrtle Av turn their backs on Mayor de Blasio as spoke at — Joe Jackson (@joejackson)December 27, 2014

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

Another reporter on the scene said that, earlier in the morning, the mayor had to walk past a police officer carrying signs that read "Dump de Blasio" and "God Bless the NYPD."

Lynch and the police union — which has roughly 24,000 members — had previously circulated a petition requesting that the mayor not attend funerals for officers killed the line of duty. The animosity reportedly dates back to 2013, when de Blasio supported legislation to halt the NYPD's controversial "stop-and-frisk" tactic.

De Blasio also took heat for saying recently that he had to teach his biracial teenage son to "take special care in any encounter he has with police officers," and that "we have to have an honest conversation in this country about the history of racism and the problem that has caused parents to feel their children may be in danger in their dynamics with police."

The AP reported that Lynch and de Blasio nodded at each other as they exited the church Saturday and lined up to wait for Ramos' casket.

Vice President Joe Biden and New York Governor Andrew Cuomo also spoke at the ceremony Saturday, and the officers that turned their backs on de Blasio reportedly applauded when Biden called the NYPD "the finest police department in the world."

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

NYPD helicopters performed a synchronized flyover of New York in tribute to Ramos, and video from the scene showed police officers stretched around the block to mourn their fallen colleague, a 40-year-old father of two who was studying to become a pastor.

10s of thousands of cops salute during helicopter flyover as Taps is played for — James Ford (@jamesfordtv)December 27, 2014

New York police commissioner Bill Bratton, who spoke after de Blasio, announced that Ramos had been named honorary chaplain of the NYPD's 84th Precinct. Bratton previously expressed support for the mayor and voiced disapproval of NYPD officers turning their backs on him, but said the action was reflective of the anger felt by many in the department.

"He was a father, a son, a brother, and a husband," Bratton said of Ramos. "He was a New Yorker. He was a New York City Police Officer. And he was — he is — a hero."

Funeral plans for Ramos' partner, Officer Liu, have yet to be announced.