Austria narrowly avoided becoming the first EU country to elect a far-right candidate as head of state, as postal ballots decided a knife-edge presidential run-off vote in favour of his environmentalist rival.
After an election that had been too close to call last night, a count of the absentee votes this morning pushed 72-year-old Alexander van der Bellen past anti-immigration Freedom Party rival Norbert Hofer and into the largely ceremonial post of president.
The Freedom Party and its resurgent European allies expressed disappointment at the defeat but delight at the surge in support for them from Austrian voters.
Traditional parties of government meanwhile, expressed relief.
"Fifty percent confidence in Norbert Hofer is a gigantic showing," Mr Hofer's campaign manager Herbert Kickl told public broadcaster ORF, toning down comments before the election that suggested the Freedom Party might contest the count.
"One thing is clear: there are many Norbert Hofers in the Freedom Party and we are very, very well placed for parliamentary elections - whenever they come," he added.
"This is just the beginning," FPO leader Heinz-Christian Strache said on his Facebook page.
One factor behind the strong FPO showing was dissatisfaction with the feuding ruling coalition of two centrist parties.
Opinion polls regularly suggest the Freedom Party would win parliamentary elections if held now. The current government's term runs until 2018.
The Interior Ministry count gave Mr van der Bellen 50.3% of the vote, compared to 49.7% for Mr Hofer, who had run on an anti-immigration platform.
The margin of victory was just over 31,000 out of nearly 4.5 million valid votes cast.
Mr Hofer conceded defeat in a post on his Facebook page, thanking his supporters and telling them not to be despondent.
"Of course I am sad today," he said. "I would have liked to take care of our wonderful country for you as president."
Mr Hofer's defeat averts a big potential embarrassment for Europe's political establishment, increasingly under threat from populist parties that have profited from concerns about the refugee crisis, weak growth and high unemployment.
"It's a relief to see the Austrians reject populism and extremism," French Prime Minister Manuel Valls said on Twitter. "Everyone in Europe must draw lessons from this."
Austria has been at the centre of a record influx of migrants, fanning resentment towards the two centrist parties - the Social Democrats and the conservative People's Party - that have dominated politics since the end of World War II.
Yesterday’s provisional result, which did not include the postal ballots, had shown Mr Hofer ahead.
But the SORA institute, a pollster, said that mail-in ballots were likely to favour former the Greens leader because they are traditionally used by more educated voters.
The vote in Austria, a country of 8.5 million people, had unsettled leaders elsewhere in Europe, particularly in neighbouring Germany where the new anti-immigration Alternative for Germany is on the rise.
In France, the National Front of Marine Le Pen is leading in polls ahead of a presidential election next year.
"Despite the disappointment, a historic score for our ally from the FPO," National Front Secretary General Nicolas Bay said on Twitter. "The future belongs to patriots!"
Across the Channel, the UK Independence Party is campaigning for Britain to leave the European Union in a referendum on 23 June.
Mr Hofer, 45, has described himself as a centre-right politician and told voters not to believe suggestions from other parties that he would be a dangerous president.