The new head of Austria’s Social Democrats vowed to move the party past "one of its bitterest moments" Tuesday after a bizarre mix-up that initially saw his rival declared the winner in a leadership contest.

The center-left opposition party, the second-biggest in Austria's parliament, announced on Monday that Andreas Babler — the mayor of the town of Traiskirchen, who was viewed as an outsider — had in fact won the leadership. At a party convention Saturday, Hans Peter Doskozil, a provincial governor and former defense minister, had been declared the winner.

The party said the two candidates' votes had been counted correctly but switched when the results were entered in an Excel spreadsheet. Before accepting the leadership, Babler called for a recount with a notary present, which took place Tuesday — confirming that he took 317 votes to Doskozil's 280.

The head of the Social Democrats' electoral commission, Michaela Grubesa, resigned Tuesday. Her successor, Klaudia Frieben, said as she confirmed the outcome that fraudulent intentions were ruled out in the original result.

"You can all imagine that what happened yesterday surprised me just as much as it did all of you," Babler, a 50-year-old left-winger, told reporters in Vienna. "The mistake that happened here shamed the Social Democrats, and I would like to apologize again today."

SPREADSHEET ERROR CHANGES OUTCOME OF AUSTRIAN OPPOSITION PARTY'S LEADERSHIP ELECTION

Europe Fox News graphic

The new head of Austria’s Social Democrats has taken over the role after a leadership mixup.  (Fox News)

CLICK HERE TO GET THE FOX NEWS APP

"I ran as leader to restore our party's unity, pride and dignity, and recent days have shown how bitterly necessary that is," he said. A national election is expected next year.

The leadership debacle followed months of tensions. The previous leader, Pamela Rendi-Wagner, was assailed for a perceived lack of vision and for an inability to capitalize more on public dissatisfaction with the government, a coalition of conservatives and environmentalist Greens.

Rendi-Wagner bowed out after finishing third in an initial ballot of party members, in which Doskozil — long her main rival — narrowly finished first.

"We have to be honest and say that the Social Democrats are pretty much on the floor now," Babler said. "This party is experiencing one of its bitterest moments of recent decades," he added, saying he wouldn't be surprised if its poll ratings worsen further "after this theater."

"But we will write the future of the Social Democrats ourselves," he said.

The far-right opposition Freedom Party, which has benefited from voters’ frustration with rising inflation, has led recent Austrian polls.