Bill de Blasio is fortunate in one way and one way only this week.

Unlike New York City’s last Democratic mayor, who found himself at cross purposes with his own police force a year before he had to stand for re-election, de Blasio has almost three years left before he faces voters in the Democratic primary in September 2017.

That means he has time to make things right. David Dinkins, who was mayor for a single term until his ouster by Rudy Giuliani in 1993, didn’t have that luxury. Dinkins’ difficult relationship with the NYPD became irredeemable in the summer of 1992.

Nothing de Blasio has yet done can compare to the grave offense Dinkins committed that summer, when he literally threw the city’s support behind a drug dealer and implicitly threw a cop to the wolves. Here’s the story:

In July 1992, Jose “Kiko” Garcia confronted Officer Michael O’Keefe in a Washington Heights stairwell and ended up dead.

Two supposed eyewitnesses said they saw the cop beat ­Garcia and then execute him.

The Dominican community ­exploded in rage. In response, Dinkins visited Garcia’s family on two occasions and had the city pay for his funeral.

The eyewitnesses were lying. An extensive investigation uncovered irrefutable evidence that Garcia had actually ambushed O’Keefe. Garcia had been portrayed as an innocent kid living with his mother and struggling to make ends meet working in a ­bodega.

Instead, he was almost certainly serving as a lookout for a cocaine den — the apartment of one of the two “witnesses.”

Relations between Dinkins and the NYPD had already gone sour because he had appointed a civilian board to look into allegations of police brutality and had opposed (along with his police chief) arming cops with more powerful guns — this at the height of the city’s drug crime wave.

After the Manhattan district attorney told the truth about Garcia and cleared Michael O’Keefe’s shamefully dirtied name, 10,000 police officers gathered at headquarters to demonstrate against Dinkins.

Barricades were set up; the cops stormed through them, shouting Al Sharpton’s signature phrase: “No justice, no peace.”

Standing there, right with them, was Dinkins’ once and future opponent, Rudolph Giuliani.

His presence scandalized The New York Times, but it helped solidify the idea in the next election that there was one mayoral candidate who stood with those who were trying to protect the citizens of New York from the Kiko Garcias of the world and one who was not.

Of course, 2014 is not 1992, when the Dinkins administration really began falling apart.

The city is not awash in crime, as it was then. In ’92, the general sense was that New York was rotting from the inside. Now, crime feels like the exception rather than the rule. The city is the safest it has ever been.

Demonstrators beg to differ. They claim black people are at special and heightened risk from cops.

They argue this in a city in which a police force of 34,000 serving in a city of 8 million residents discharged bullets from their weapons exactly 81 times in 2013 — compared to 312 in 1993.

Nationwide, “police could end all killings of civilians tomorrow and it would have no effect on the black homicide risk,” writes City Journal’s Heather Mac Donald. “In 2013, there were 6,261 black homicide victims in the US — almost all killed by black civilians.”

Nonetheless, it has become acceptable, in the face of all countervailing evidence, to argue that New York’s police officers hold black lives cheap. And what New York’s police officers now know is that this is a view shared by their boss — the city’s mayor.

He said as much when he proudly informed the world he had warned his own biracial son to beware the cops.

In doing so, he did not sink to Dinkins’ level in the matter of Kiko Garcia. But in delineating a hostile racial divide between his own family and the police, he did something emotionally abusive to 34,000 people who work for him.

After a fanatic assassinated two cops on Saturday, de Blasio clearly understood he had to do something to calm the waters between himself and the NYPD.

But it was telling that de Blasio could not restrain himself during a press conference he called on Monday to try to set things right with the NYPD — reserving his greatest passion for an unplanned defense of anti-cop demonstrators against the media.

So, yes, he has three years to fix things. Problem is, he’s Bill de Blasio.

And Bill de Blasio gives every indication that, left to his natural instincts, he’ll just make things worse.