NEW YORK (AP) — Thousands of police officers lined the pews Friday at St. Patrick’s Cathedral to honor fallen Officer Jason Rivera, who was gunned down with his partner last week in an ambush that left the New York Police Department in mourning and the city on edge.

Mayor Eric Adams, himself a retired police captain, told those gathered that he saw an echo of himself in the slain officer who had joined a department he had seen as flawed in hopes of improving it.

“He did it for the right reasons — he wanted to make a difference,” said Adams, a Democrat who also sounded a message of support for a force that, like other police departments, has come under criticism amid a national reckoning with policing, race and what public safety should mean.

“There were days when I felt the public did not understand and appreciate the job we were telling, and I want to tell you officers: They do. They do,” he said. “These two fine men watered the tree of safety that allows us to sit under the shade from the hot sun of violence.”

Officers came from near and far to honor Rivera, 22, who was recently married and barely into his second year of service on the force.

“It doesn’t really matter what uniform we wear,” said Master Police Officer Tammy Russel, from Fairfax County, Virginia. “These are all our brothers and sisters. … Sadness all around.”

Story continues below.

Rivera and a partner, Officer Wilbert Mora, were fatally wounded Jan. 21 by a gunman who ambushed them in a hallway as they responded to a family dispute. Mora’s funeral is being held next week, also at St. Patrick’s.

Both officers grew up in the city’s ethnic enclaves and had hoped to help the department build bridges with the community. Friends and fellow police officers describe them as caring and dedicated.

Roman Catholic Cardinal Timothy Dolan presided over Rivera’s service, held in Spanish and English in recognition of his Dominican heritage. A day earlier, everyday citizens joined thousands of uniformed officers at the cathedral for Rivera’s wake.

New York Gov. Kathy Hochul said flags at state buildings would fly at half-staff from sunrise the day of Rivera’s funeral until sunset the day of Mora’s funeral on Wednesday.

“It’s an emotional time,” said retired NYPD Officer Sean Flanagan, who played the bagpipes outside the cathedral. “We honor our own, we take care of our own.”

The gunman, who was shot by a third officer, died earlier in the week. Authorities are still investigating why he fired at the officers.

Before Friday, the last NYPD officer killed in the line of duty was Anastasios Tsakos, who was struck by a suspected drunken driver in May 2021 while assisting officers at the scene of an earlier crash on a Queens highway.

The last NYPD officer fatally shot in the line of duty, Brian Mulkeen, was hit by friendly fire while struggling with an armed man after chasing and shooting at him in the Bronx in September 2019.

Two officers, Randolph Holder and Brian Moore, were killed in separate shootings in 2015. The year before, Officers Wenjian Liu and Rafael Ramos were fatally shot by a man who ambushed them as they sat in their patrol car in Brooklyn.