Former Metropolitan Transit Authority Chairman Joe Lhota easily won the GOP nomination, capping a chaotic primary to succeed 12 years of Mayor Michael Bloomberg. The night also marked the unceremonious end to the bid by a City Council leader trying to become the first female and openly gay mayor, and to the political comebacks of scandal-scarred candidates Anthony Weiner and Eliot Spitzer.
"We are better as a city when we make sure that everyone has a shot," de Blasio told his raucous Brooklyn victory party, emphasizing his campaign theme of combatting income inequality.
With 97 percent of precincts reporting, de Blasio has about 40.2 percent of the total vote. He needs to stay above 40 percent in order to avoid triggering an automatic Oct. 1 runoff. If he cannot, he will face former city Comptroller Bill Thompson, who has 26 percent.
Council Speaker Christine Quinn was third at 15 percent, followed by current city Comptroller John Liu at 7 percent and Weiner at 5 percent. Elections officials are going to recount the ballots cast Tuesday and are expected to count an additional 30,000 or more votes in coming days as absentee ballots arrive by mail and paperwork comes in from voters who had problems at the polls. A final result may not be known for 10 days.
With de Blasio so close to 40 percent, Democratic leaders may pressure Thompson to drop out in the name of party unity. But Thompson made it clear Tuesday that he wanted to contest the runoff.
"Three more weeks! Three more weeks!" chanted Thompson, the party's 2009 nominee, referring to the campaign sprint before the potential runoff. "This is far from over."
Exit polling shows that de Blasio would handily defeat Thompson in a runoff, 52 to 34 percent, with 9 percent saying they'd stay home.
De Blasio's rise in the race to succeed Bloomberg was as sudden as it was unexpected.
Not even two months ago, he was an afterthought in the campaign but surged in part thanks to an ad blitz that centered on his interracial family, his headline-grabbing arrest while protesting the possible closure of a Brooklyn hospital and the defection of Weiner's former supporters in the wake of another sexting scandal.
The exit polling showed the appeal of de Blasio, who holds the position of the city's official watchdog, to be broad-based: He was ahead in all five boroughs; was even with Thompson, the only African-American candidate, with black voters; and was ahead of Quinn, the lone woman in the race, with female voters.
The voter interviews were conducted by Edison Media Research for The Associated Press and other news organizations.
The winner of any runoff contest will face Lhota in the Nov. 5 general election. Lhota, ex-MTA chairman and former deputy mayor to Rudolph Giuliani, defeated billionaire grocery magnate John Catsimatidis for the GOP nomination.
In the closely watched race for city comptroller, Manhattan Borough President Scott Stringer defeated Spitzer, who was seeking a return to politics after resigning New York's governor's office in 2008 amid a prostitution scandal.
The winner of the mayor's race in November will assume the helm of the nation's largest city at a critical juncture, as it experiences shrinking crime rates yet widening income inequality, and as the nearly completed One World Trade Center building symbolizes a new era after the terrorist attacks of 2001.
Bloomberg, the businessman Republican-turned-independent, is completing his third term. While the city's registered Democrats outnumber Republicans 6 to 1, the GOP's recent success in mayoral elections has been largely attributed to a crime epidemic, the aftermath of the Sept. 11 attacks or other extraordinary circumstances.
Nearly three-quarters of Democratic primary voters say the next mayor ought to move away from Bloomberg's policies, according to the exit polls.
And De Blasio, 52, has fashioned himself as the cleanest break from the Bloomberg years, proposing a tax on the wealthy to fund universal pre-kindergarten and changes to city police practices he says discriminate against minorities.
"I'm a lefty and I've had enough of the righties," said Jessica Safran, a business consultant from the Boerum Hill section of Brooklyn who voted for de Blasio. "Even if de Blasio moves to the center if he gets elected, he'll be closer to the positions I want than the others."
Quinn was the front-runner for much of the year, boasting the biggest campaign war chest and strong establishment backing. But she was dogged by her support to change term limits to let Bloomberg run again in 2009, a decision unpopular with liberals who make up the bulk of Democratic primary voters.
Turnout appeared light, but the city's complaint line received several thousand voting-related calls. Many reported jams and breakdowns in the antiquated lever machines, which were hauled out of retirement to replace much-maligned electronic devices.
The mayoral campaign was waged in hundreds of candidate forums and across millions of dollars of TV ads and was largely fought on the legacy of the Bloomberg era. Substantial policy differences were scarce among the Democrats, who agreed that the school system needed an overhaul, that the city's poor had been forgotten, and that stop-and-frisk police tactics used to stop suspicious people needed changing amid claims that police unfairly targeted blacks and Latinos.
Weiner surprisingly entered the race in May after being in political exile since resigning from Congress in 2011 upon admitting to lewd online exchanges with women who were not his wife.
His candidacy sparked curiosity and popular interest, and he immediately shot to the top of the polls. But support collapsed almost as quickly when he revealed in July that he continued the online behavior even after his resignation from federal office. In a fitting end to a campaign that could not escape the shadow of his scandal, the woman with whom he chatted last summer, college student Sydney Leathers, tried to crash Weiner's primary night rally, where the candidate choked up giving his concession speech. She did not get in.
On the Republican side, the candidates largely pledged to follow Bloomberg's lead, focusing on maintaining the city's record low crime rates. Lhota led the race from start to finish, fending off Catsimatidis' self-financed, unorthodox bid. Catsimatidis spent more than $4 million of his own money but was unable to stage a serious challenge.
Contributing to this report were Associated Press video journalist Ted Shaffrey and Associated Press writers Jim Fitzgerald, David B. Caruso, Nick Divito, Larry Neumeister and Jake Pearson.
Follow Jonathan Lemire at http://www.twitter.com/JonLemire