Austria's highest court has annulled the result of the presidential election narrowly lost by the candidate of the far-right Freedom Party.
The party had challenged the result, saying that postal votes had been illegally and improperly handled.
The Freedom Party candidate, Norbert Hofer, lost the election to the former leader of the Greens, Alexander Van der Bellen, by just 30,863 votes or less than one percentage point.
The election will now be re-run.
Announcing the decision, Gerhard Holzinger, head of the Constitutional Court, said: "The challenge brought by Freedom Party leader Heinz-Christian Strache against the 22 May election... has been upheld."
He added: "The decision I am announcing today has no winner and no loser, it has only one aim: to strengthen trust in the rule of law and democracy."
Will Brexit matter, asks Bethany Bell, BBC News, Vienna
Austria's politics have been thrown into confusion. One of the most controversial and polarising presidential elections in recent history will have to be re-run.
This is a moral victory for the far-right, anti-immigrant and Eurosceptic Freedom Party, which launched the legal challenge last month after alleging "terrifying" irregularities.
The Freedom Party is hoping that the decision by the court will help its candidate Norbert Hofer win in the new election this autumn.
Hanging over the vote is the shadow of "Brexit" - the UK's decision to leave the EU.
Will Mr Hofer choose to make Austria's future membership of the EU a campaign issue?
Some Austrians think the vote by the United Kingdom to leave the EU could boost populist and nationalist sentiment in Austria. Others believe the political turbulence in Britain may make people more cautious about Eurosceptic parties.
Mr Hofer said on Friday he was pleased that the court had taken "a difficult decision", adding: "I have great trust in the rule of law."
Mr Van der Bellen said he was "very confident" he would emerge the winner.
"Austria needs to be well represented in Europe and the world. If we can do it once, we can do it again," he told reporters.
Austrian Chancellor Christian Kern said the court ruling showed that the country's democracy was strong and he called for "a short campaign, a campaign without emotions".
In two weeks of hearings, lawyers for the Freedom Party argued that postal ballots were illegally handled in 94 out of 117 districts.
It alleged that thousands of votes were opened earlier than permitted under election rules and some were counted by people unauthorised to do so.
The party also claimed to have evidence that some under-16s and foreigners had been allowed to vote.
In its ruling, the court said election rules had been broken in a way that could have influenced the result.
But it said there was no proof the count had been manipulated.
If elected, Mr Hofer would become the first far-right head of state of an EU country.
His party has based its election campaigns around concern over immigration and falling living standards for the less well-off.
After Britain voted to leave the EU, Mr Hofer said he favoured holding a similar referendum in Austria if the bloc failed to stop centralisation and carry out reforms "within a year".
Last Sunday, he told the Oesterreich newspaper (in German): "If [the EU] evolves in the wrong direction, then in my opinion the time has come to ask the Austrians if they still want to be part of it."
His opponent, Mr Van der Bellen, is strongly pro-EU and has spoken of his dream for a border-free "United States of Europe".
The two men went forward to a run-off when, for the first time since World War Two, both the main centrist parties were knocked out in the first round of voting.
Following the court's order to re-run the vote, President Heinz Fischer will be replaced on a temporary basis by three parliamentary officials, including Mr Hofer.
The new election is expected to be held in September or October.
What powers does the Austrian president have?
It is a mostly ceremonial post. But the president does have the power to dissolve the National Council - the more powerful lower house of parliament. That triggers a general election.
The president can only do that once for a particular reason - he cannot use the same grounds to dissolve it again.
It is the chancellor's job to appoint government ministers. And the chancellor has the power to dismiss the government. But ministers have to be formally sworn in by the president.
Vying to lead Austria
- Age: 45
- Background: Aeronautical engineer
- Politics: Far-right Freedom Party
- Campaign soundbite: "To those in Austria who go to war for the Islamic State or rape women - I say to those people: 'This is not your home'."
Alexander Van der Bellen
- Age: 72
- Background: Economics professor
- Politics: Former Green Party leader
- Campaign soundbite: "I've experienced how Austria rose from the ruins of World War Two, caused by the madness of nationalism."