NEW YORK – One of the most unpredictable and contentious primary campaigns the city has seen in decades is drawing to a close. And on Tuesday, for the first time since 1997, voters will not see Michael Bloomberg’s name on their mayoral ballot.

Bloomberg has defined New York City for 12 years, largely setting party politics aside as he led with his data-driven convictions and his immense fortune. Both parties are now grappling with his legacy — the Republican mayoral hopefuls are largely promising to maintain his policies, while the Democrats have offered a sharply different approach.

Their front-runner is pitching himself as the cleanest break with the current administration.

Bill de Blasio, the public advocate, enters primary day with a commanding lead in the polls, a reversal of fortune from six weeks ago, when his campaign was mostly an afterthought. But several events coincided to give him late momentum:

He fought a proposed closure of a Brooklyn hospital, even getting arrested for his efforts, which gave a much-needed shot of publicity.

His interracial family, especially his Afro-sporting 15-year-old son, became the center of his advertising campaign. That prompted Bloomberg to call de Blasio’s campaign “racist,” putting de Blasio’s rivals in the unwelcome position of having to defend the public advocate.

And former front-runner Anthony Weiner succumbed to another sexting scandal, prompting many of his supporters to defect to de Blasio.

In a Quinnipiac University poll released Monday, de Blasio was the choice of 39 percent of likely Democratic voters, just shy of the 40 percent needed to avoid an Oct. 1 runoff between Tuesday’s top two finishers.

De Blasio has adopted the mantle of the clear favorite. But that Quinnipiac poll, which surveyed 782 Democrats and has a margin of error of 3.5 percentage points, also suggested that 18 percent could change their minds.

If de Blasio’s support holds, the other spot in the potential runoff appears to be a battle between City Council Speaker Christine Quinn and former comptroller Bill Thompson.