Bill De Blasio, the liberal pragmatist who sprang from nowhere to storm the Democratic race for New York mayor, was within a hair's breadth of winning his party's nomination outright on Wednesday.

Unofficial tallies put De Blasio at 40.2%, just over the 40% needed to avoid a run-off on 1 October. A decisive result would place De Blasio in the front-runner position for the November general election, where he would go up against the former chief of New York's transport agency, Joe Lhota, who won the Republican nomination.

But official results put him just under 40% and should a final count force De Blasio to go to a second round, he would go face Bill Thompson, the city's former comptroller, or chief auditor, who took second place with 26%. Christine Quinn, the city council leader and early favourite, was beaten into a distant third place.