NEW YORK — Anthony Weiner’s ill-fated mayoral campaign ended with a string of final embarrassments: He mustered a mere 5 percent at the ballot box. One of his sexting partners tried to crash his primary night rally. And Weiner was caught making an obscene gesture to reporters as he was driven away.

Outside a “victory” party where supporters mourned a disappointing fifth-place finish in the Democratic primary, cameras crowded around Sydney Leathers, the 23-year-old whose sexting with the former congressman brought his once-high-flying campaign to a screeching halt.

“Why not be here?” Leathers asked reporters. “I’m kind of the reason he’s losing. So, might as well show up.”

Another politician with a sex scandal, Eliot Spitzer, lost the Democratic primary contest for city comptroller to Scott Stringer, the Manhattan borough president. Stringer took 52 percent of the vote to Spitzer’s 48 percent.

Spitzer resigned as governor in 2008 and admitted he paid for sex with call girls. In exile, he bounced around television as a pundit. Then, just four days before the deadline, he announced he was running for comptroller.

On the final campaign day for both men, the spotlight fell heavily on Weiner. His staff sneaked him into his own event, presumably to avoid Leathers, who had camped outside his headquarters all day hoping to confront him. His wife, Huma Abedin, who stood by his side at the height of the scandal, was nowhere to be seen.

And after a concession speech in which he got choked up as he spoke of family, a scowling Weiner was caught by a photographer giving a middle-finger goodbye to reporters as he was driven away.

Leathers, who has launched a porn career since the scandal broke, said Weiner needed “to stop being an embarrassment to the city of New York. He’s going to continue this behavior. If it’s not going to be me, it’s going to be some other girl.”

At one point, one of Weiner’s supporters scolded Leathers, saying: “You must really be ashamed!”

For his part, Weiner acknowledged in his concession speech that he was an “imperfect messenger” but also boasted of the staying power of himself and his campaign.

Weiner had been in political exile since he resigned from Congress in 2011 for sending women lewd online messages and pictures. He got into the mayor’s race in May, and aside from a few dust-ups with hecklers, was largely well-received at first, holding the lead for most of June and July.

But after an obscure gossip website named The Dirty released X-rated exchanges between Weiner and Leathers that took place well after the candidate quit the House of Representatives, Weiner — and his sexting pseudonym, Carlos Danger — once again became a national punchline.

With 98 percent of precincts reporting Wednesday morning, Weiner was far behind in the city’s Democratic mayoral primary. Public Advocate Bill de Blasio had 40 percent of the vote, the threshold needed to avoid triggering an automatic Oct. 1 runoff. If he cannot maintain that, he will face former city Comptroller Bill Thompson, who has 26 percent, for a potentially grueling three-week showdown, with the winner advancing to face Republican nominee Joe Lhota in the general election.

Spitzer took a steadier path to his loss. He took an early lead in the polls, but the race tightened dramatically in recent weeks as the Democratic establishment rallied around Stringer, his main opponent.

Unlike Weiner, who made a point of fielding voters’ questions about his scandal, Spitzer apologized a few times and then refused to talk about it.

He largely eschewed retail campaigning — situations that could have led to awkward exchanges with voters — in favor of national TV interviews and a big television ad campaign, financed with his own millions.

But he could not avoid all mention of the scandal. The city’s tabloids hounded him about the state of his marriage; Spitzer said he was still married, but his wife never appeared on the campaign trail.

“All of us should serve, participate,” Spitzer told supporters in his concession speech. “I intend to do so in different ways.”

——

Associated Press Radio Correspondent Julie Walker and AP Videojournalist Bonny Ghosh contributed to this report.