Mayor de Blasio tried to make peace with the NYPD Saturday but again collided with the Blue Wall of Resentment.

As he took the podium Saturday at the funeral of slain Officer Rafael Ramos, thousands of cops outside the church turned their backs to the video monitors showing the mayor delivering his eulogy inside.

In a gradual wave, the assembled cops nearest the screens and speakers on Myrtle Avenue in Queens began to about-face, until the entire sea of blue stretching two blocks had their backs to the image of the city’s leader.

“Our hearts are aching today. We can feel it physically. We feel it deeply. New York City has lost a hero — a remarkable man because of the depths of his commitment to all around him,” de Blasio said of Ramos.

As he acknowledged the fallen officer’s family, the mayor reached out to the rank-and-file.

“I extend my condolences to another family — the family of the NYPD that is hurting so deeply right now,” said de Blasio.

Officers outside maintained a stony silence throughout the eulogy until de Blasio began to speak in Spanish, which prompted snickers.

The Democratic mayor did find a sympathetic ear in the unlikely form of a Republican predecessor — Rudy Giuliani.

The ex-prosecutor famous for pushing the “broken windows” style of policing when he was mayor — a tactic now under attack by protesters — approached de Blasio when the service ended and the hearse departed.

“We may differ in politics, but when it comes to the safety of this city and our police officers, I am there. I will be supporting you,” Giuliani said.

“Thank you very much, glad to have your support,” de Blasio ­replied, according to a pol who witnessed the exchange.

De Blasio — who union officials have said has “blood on his hands” for rhetoric that created a dangerous atmosphere for cops and led to the assassinations of Ramos and his partner, Officer Wenjian Liu — arrived 30 minutes early at the 10 a.m. service at Christ Tabernacle Church with wife Chirlane McCray.

A huge crowd of officers refused to acknowledge de Blasio, who quietly greeted Police Commissioner Bill Bratton and his wife before slipping into the funeral home adjoining the Glendale church through a side door.

The execution of Ramos and Liu as they sat in their patrol car in Brooklyn sparked a tidal wave of anger toward the mayor from the city’s cops, who turned their backs to him as he walked through a hospital corridor a week ago Saturday night after visiting the officers’ grieving families.

Earlier that night, when de Blasio approached a group of NYPD Finest and said, “We’re all in this together,” a stone-faced officer replied, “No, we’re not.”

Many cops have blamed de Blasio for helping to create a climate of distrust of law enforcement, turning them into targets as protests against police swept through the city in the wake of a Staten Island grand jury’s decision not to indict a cop in the July death of Eric Garner.

Things got so heated in the weeks leading up to the killings of Ramos and Liu that the Patrolmen’s Benevolent Association demanded that de Blasio stay away from the funerals of officers killed in the line of duty.

A coalition of retired NYPD cops took their anger to new heights Friday by hiring a pilot to fly over the city for hours with a banner reading, “De Blasio, our backs have turned to you.”

After the funeral, about 100 police officers, firefighters and others who had stood vigil for ­Ramos made their way to Teedee’s Tavern, about two blocks from the church.

A firefighter hopped up onto a table, a beer in one hand and a camera in the other, taking pictures of the packed bar.

“Here’s to Ramos! Here’s to the NYPD!” he shouted, to the cheers of those assembled.

“And f–k de Blasio!” he added, raising a raucous response from the crowd.

Garry McCarthy, who served 25 years with the NYPD and is now head of the Chicago Police Department, said the tension between the NYPD and de Blasio “is painful to watch.”