Austrian far-right Freedom Party leader Heinz-Christian Strache, left, and Freedom Party presidential candidate Norbert Hofer at a rally in May. (Leonhard Foeger/Reuters)

Austria’s high court on Friday voided the results of May’s presidential election and ordered a new vote, opening a fresh opportunity for a far-right party and posing new risks for the European Union as it reels from the historic British vote to leave.

The unprecedented decision sets up a replay of a bitter election that brought a sigh of relief from the E.U. political establishment when the candidate for the far-right Freedom Party lost by slightly more than 30,000 votes.

The court ruled in favor of a petition by the Freedom Party to throw out the May result based on the mishandling of thousands of absentee ballots — more than enough to potentially swing the outcome.

Heinz-Christian Strache, the Freedom Party’s chief who had filed the complaint, called the verdict a “victory for democracy.”

Meet the European leaders hoping to cause the next Brexit

“This was no sloppiness, but massive legal irregularities,” he said.

A Freedom Party victory in a new election would usher in Western Europe’s first far-right head of state since World War II, emboldening populist and nativist parties across the region. Forces allied with the Austrian party in France, the Netherlands and elsewhere are already seeking to capitalize on last week’s British referendum to set up their own E.U. exit votes.

The Freedom Party’s candidate, Norbert Hofer, has called for an Austrian vote to leave the E.U. “within a year” unless the bloc makes significant reforms.

“If Hofer, in the end, is the winner, it may have cascading consequences,” said Reinhard Heinisch, head of political science at the University of Salzburg in Austria. “The Austrian government could fall, and it would be seen as a further indication that Europe is fraying not just around the edges, but increasingly at its center.”

The winner in May, Alexander Van der Bellen, a 72-year-old statesman and former Green Party politician, was due to be sworn in next week and now must watch Hofer and others temporarily fill the position.

Under Austrian law, the vacant job of president is filled in the interim by the nation’s three top parliamentarians — of which Hofer is one. That means he will assume that role, along with peers from Austria’s two main parties, starting July 8.

In Austria, the job of president is largely ceremonial — the head of government is the chancellor, currently Christian Kern of the center-left Social Democratic Party. Hofer’s vows to exert the power of his office in new ways — he threatened, for instance, to dissolve the lower house if migrants were not stopped — became one of the defining issues of the May election.

In his interim role, he will lack the power to cause waves. Although a date for the new election has not yet been set, it is expected to be in September or October.

“The decision . . . doesn’t make anyone a loser or a winner. It should only serve one purpose: to strengthen trust in our legal system and therefore our democracy,” the president of the Austrian constitutional court, Gerhard Holzinger, announced in Vienna.

The court, in its ruling, emphasized that there was no evidence of deliberate manipulation. The mishandled ballots — absentee ballots were opened before the deadline and counted without proper monitoring — appeared mostly the byproduct of sloppy management. The irregularities affected a total of 77,926 votes, more than double the number of ballots that swung the election.

The court also declared that government officials’ practice of leaking information to the media on early results was “unlawful.”

Speaking Friday in Vienna, Hofer cast doubt on whether the ballots had been properly tallied.

“What these people did is beyond my knowledge,” he said.

It remained unclear how the aftermath of Britain’s exit vote would influence the Austrian campaign. On one hand, the hit to the British pound and economic turbulence could lead some Austrians to stick to the status quo. But with the vote still some months off, analysts suggested a calming of the crisis over Britain by then could also work in Hofer’s favor.

Kern, the Austrian chancellor, said he hoped for cool heads in the new campaigning.

“I’m now hoping for a short campaign,” Kern said, “a campaign that’s not led by emotions.”

Stephanie Kirchner contributed to this report.