Past and future mayors?

After nearly a week without a cigarette — 133 hours as I write this, but who’s counting? — I’m having a weird New York City nightmare.

My brain keeps bouncing around what the great historian David Hackett Fischer calls the “causal power of particular actions and contingent events” — how fraught and unlikely the stuff that becomes history is as it happens, and how settled and inevitable it can seem after the fact.

Flashback to 1989, when Manhattan Borough President David Dinkins stepped up for what seemed like a longshot primary challenge to three-term mayor Ed Koch. The story, as told to me years later by a Koch confidant , was that Dinkins, in what in hindsight was a sign of troubles to come on his watch, botched his petitions and could have been knocked off the ballot.

But looking ahead to an anticipated general election faceoff against star prosecutor Rudy Giuliani, whose path to victory was predicated on peeling off 25% or so of the black vote from Koch, the mayor opted not to knock off his rival .

When Dems then dumped Koch for Dinkins, Giuliani, now with no shot at black voters, jerked into a new role as the candidate of outer borough white ethnics, only to fall just short in November.

After four years of record-high crime, race riots and near bankruptcy under Dinkins, the two faced off again. This time Giuliani started off committed to his political role, culminating in his 1992 turn as emcee at a cop rally turned riot, complete with racial slurs and slashed tires.

Basically no one changed their vote, but a Staten Island succession ballot and a few new Asian voters proved just enough to turn the city’s first black mayor into a one-term footnote, the one break in a chain spanning four decades, from Ed to Mike, of the overwhelmingly Democratic city electing neo-liberal mayors.

Forward to 2001, when the Democratic primary, slotted for Sept. 11, was postponed for two weeks after the planes hit the Twin Towers. If the attack had come just a day later, Ferrer would likely have been the Democratic candidate, on track to become the city’s first Hispanic mayor.

Instead, Bloomberg got to face off against Mark Green after a racially incendiary Democratic runoff that — shades of what Rudy had hoped for in 1989 — helped the outsider peel off black and Hispanic votes. In a race that amounted to a referendum on the other guy, Bloomberg did and spent just enough to get to City Hall with a fairly clean slate. If he’d instead faced and somehow bested Ferrer, he would have come to office as a far more divisive mayor.

And forward again to 2013, when shady horse money kneecapped Chris Quinn, a shady Campaign Finance Board decision decapitated John Liu and a second public outbreak of his shady social habits forced Anthony Weiner to pull out. That all combined to give de Blasio a last-minute, wide-open lane. He went the back of the Democratic field just weeks before the primary to a 50-point win in November with the same “tale of two cities” slogan that made a 20-point loser of Ferrer eight years earlier.

Which, good for Blas. You’ve got to be good to be lucky, lucky to be good. But the insistence in politics, as in sports, that victory measures mettle is a bit much. Strange things can happen on any given Tuesday.

When de Blasio prattles on about how the 20 years before him were anomalous, he’s partly right. But when he offers himself as the city’s true will reasserting its course after a long detour, his terrible poll numbers make clear he’s mostly just kidding himself.

The mayor keeps framing that as a failure of messaging, not substance, but that may be beside the point. Like the coach said, you’re as good as your record, and de Blasio’s next game isn’t until next November.

With City Hall fretting that de Blasio could become in a sense the second black, progressive mayor New Yorkers dump after one tough term, he’s been pressing the political reset button like a test-lab rat for months , culminating in a December breakfast with business poobahs where the great progressive hope vowed to sweep the street homeless out of the vast business district.

But if de Blasio hoped winter would help buy him time, Gov. Cuomo and other hostile Democrats, sensing weakness, have kept the story about his real and perceived failings on the front pages, feeding what’s become a persistent impression of a city on the slide , even as underlying indicators (crime, the economy, etc.) show otherwise.

Flashback to 2001: The last time it looked like the Democratic regulars were returning to power, stuff happened and we instead elected a mayor with a twisted pitch (one delivered largely through tens of millions in TV ads) about how money corrupts, so we needed a rich guy who can’t be bought off.