Anthony Weiner's controversial bid to become New York City mayor ended sourly with the sex scandal-dogged candidate giving the finger to reporters after leaving the venue where he had given his concession speech.

Weiner, who was leading the race for the Democrat nomination before being embroiled in a replay of the online flirting scandal that cost him his congress seat in 2011, came fifth with just 5% of the vote.

An angry Weiner, 48, made the middle-finger gesture to the cameras of CNN affiliate NY-1 as he was driven away from a Manhattan bar that had been turned into election night headquarters.

Weiner had had to sneak into the venue through a back door to avoid an embarrassing confrontation with Sydney Leathers, the 23-year-old woman who triggered his second political downfall.

Leathers leaked a number of X-rated text messages she had exchanged with the married father of one - who used the sexting pseudonym of Carlos Danger - to gossip to The Dirty website.

"I'm the reason he's losing so I might as well show up," said Leathers, who has recently embraced a career in the porn industry. "I'm here to celebrate. I think he needs some sex therapy."

In 2011, Weinter was forced to resign from congress over a similar scandal after confessing to sending lewd tweets and snaps to at least a half a dozen women.

In his concession speech Weiner acknowledged in that he was an "imperfect messenger" and got choked up as he spoke of family.

His wife Huma Abedin, a long-time aide to former US secretary of state Hillary Clinton who stood by her husband as Leathers' revelations were published, was nowhere to be seen.

The nine-candidate Democratic mayoral primary was won by New York City's public advocate Bill de Blasio, according to early unofficial results.

De Blasio won about 40% of the vote, which should be just enough to avoid a run-off with former city controller Bill Thompson.

Thompson, the sole African-American candidate, has not conceded defeat.

In the Republican race to file a candidate to replace incumbent Michael Bloomberg, Joe Lhota, the former head of NYC's transit service, won with 52%. John Catsimatidis came second with 41%.

Bill de Blasio
Democratic candidate for New York City mayor Bill de Blasio (Reuters)
Sydney Leathers New York
Sydney Leathers at Anthony Weiner’s New York City mayoral election campaign headquarters (Twitter/ Shimon Prokupecz)