In a powerful display of unity and shared grief, more than 25,000 police officers, dignitaries, and mourners from around the nation gathered in Queens on Saturday for the funeral of Rafael Ramos, one of two New York City police officers slain by an assassin one week earlier.

Wearing their dress blue uniforms, NYPD cops of every rank filled the pews inside and lined the streets outside Christ Tabernacle Church on Myrtle Avenue, where Ramos -- who was studying to become a pastor -- attended services and served as an usher.

Coming when the city seems divided between the NYPD and its supporters on one side -- and critics accusing police of abuses on the other -- the funeral served as an opportunity to heal that rift as New Yorkers came together in mourning, Police Commissioner William Bratton said.

Bratton, speaking of New York as a "city struggling to define itself," said: "If we can learn to see each other . . . to see that our cops are people like Rafael Ramos and Wenjian Liu, to see that our communities are filled with people just like them too. If we can learn to see each other, then when we see each other, we'll heal. We'll heal as a department. We'll heal as a city. We'll heal as a country."

Yet in a sign of the rifts that remain, hundreds of police officers watching on video screens outside the church turned their backs when Mayor Bill de Blasio -- who has faced intense criticism from city police unions -- spoke inside.

Ramos, 40, and his partner, Officer Wenjian Liu, 32, were gunned down in their patrol car Dec. 20 in the Bedford-Stuyvesant neighborhood of Brooklyn by Ismaaiyl Brinsley, 28, who targeted them because they were cops, police said.

Brinsley, who alluded to the deaths of Michael Brown and Eric Garner in his social media posts vowing to put "wings on pigs" before shooting Ramos and Liu, committed suicide in a nearby subway station.

Vice President Joe Biden comforted Ramos' wife, Maritza, and two sons, Justin and Jaden, calling the two fallen cops members of "the finest police department in the world."

"[Ramos] didn't just have a Bible in his locker; he lived it in his heart," Biden said. "He was a cop for all the right reasons.

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

De Blasio said all 8.4 million New Yorkers were grieving their loss.

"Our hearts are aching," the mayor said. "New York City has lost a hero."

De Blasio recalled how Ramos loved playing basketball with his sons, blasting Spanish gospel music from his car, and serving his church.

"He spent the last 10 weeks of his life studying to be a chaplain, and he was taken from us on the day he was to graduate," the mayor said.

Bratton, leading the nation's largest police force through its first line-of-duty deaths since 2011, spoke of honoring Ramos and Liu by helping bridge the divide between police and the communities they serve. He told mourners the two cops "were killed for their color. They were killed because they were blue."

"He [Ramos] represented the blue thread that holds our city together when disorder might pull it apart," Bratton said.

Mourners recalled Ramos' career path leading up to his joining the police academy at 37 -- an age when many cops are winding down their careers. Before becoming a police officer, Ramos was a carrier for DHL and later worked as a school safety officer for the NYPD's School Safety Division.

In the latter job, Ramos was assigned to the Police Officer Rocco Laurie Intermediate School -- a Staten Island school named for a cop who, along with partner Officer Gregory Foster, was assassinated by members of the Black Liberation Army in 1972 while walking their beat in Manhattan.

Ramos and Liu, per NYPD tradition, were both posthumously promoted to the rank of first-grade detective. Bratton said he was also appointing Ramos honorary department chaplain of his precinct, the 84th in Brooklyn.

Ramos, a native New Yorker of Puerto Rican descent, and Liu, a Chinese-American, were potent symbols of New York's diversity, said Cuomo, who commended the NYPD for protecting "the right of freedom of speech, even though they were the targets of false and abusive chants and tirades" in recent weeks.

"At the end of the day, we are one," Cuomo said. "One people, one state, one community, one family. Somos uno ['we are one' in Spanish]."

After the service, a group of NYPD pallbearers carried Ramos' coffin out of the church as row after row of cops -- some with tears in their eyes -- stood at attention and saluted.

"Taps" and "America the Beautiful" were played as the coffin, draped by a blue, white and green NYPD flag, passed thousands of mourners in a motorcade to Cypress Hills Cemetery in Brooklyn. A police official then handed the flag to Ramos' wife, who, flanked by her two sons, held it to her chest.

The poignant scene was witnessed by the many current and former public officials in attendance, from Rep. Peter King (R-Seaford) to former Mayor Rudy Giuliani, as well as police delegations from dozens of municipalities, including Pittsburgh, St. Paul, Minnesota, Chicago, and Nassau and Suffolk counties.

Everyday New Yorkers like Laura Cron, who, standing outside the church with her 8-year-old daughter Isabella Miceli, also were moved by the day's tributes.

"I brought my daughter so she can understand what a tragedy this really is," said Cron, 36, of Ridgewood, Queens. "Cops protect us every day."

The deaths of Ramos and Liu, Cron hopes, could lead to better discourse about race and the police.

"I hope that that's the one thing that comes out of this," she said. "Everyone deserves respect."