Far-right candidate Norbert Hofer has lost Austria's presidential election.
On Facebook, he described himself as "infinitely sad" and congratulated Alexander Van der Bellen, former head of the Greens, on his victory.
Mr Van der Bellen, 72, won with about 53% of the votes - a projection, as postal ballots are still being counted.
Although the post is ceremonial in Austria, the poll had been seen as a sign of how well populist candidates might do elsewhere in Europe.
Mr Van der Bellen called the result a vote for a "pro-European" Austria based on "freedom, equality and solidarity".
Referring to the Austrian flag, he said a "red-white-red signal of hope and change, a red-white-red signal today goes from Austria to all the capitals of the European Union.
"Finally, you know, I will try to be an open-minded, a liberal-minded and first of all a pro-European federal president of the Republic of Austria."
Sunday's vote was a rerun of May's election, which Mr Van der Bellen narrowly won, but it was marred by postal vote irregularities.
His margin in May - 30,000 votes - had now increased tenfold.
But Mr Hofer's nationalist Austrian Freedom Party (FPOe) remains a formidable force in Austrian politics. His 46.7% was the best national result to date for the FPOe.
The party's leader Heinz-Christian Strache, said: "Yesterday we wrote history!" and "Our time is coming!"
Austria's next general election is set for 2018, though it might be brought forward.
EU leaders welcomed Mr Van der Bellen's victory, which comes amid a populist challenge to established parties in much of Europe.
European Council President Donald Tusk conveyed "wholehearted congratulations" while Germany's Social Democrat Vice-Chancellor, Sigmar Gabriel, called the result "a clear victory for reason against right-wing populism".
French President Francois Hollande thanked Austria for "choosing Europe and openness".
France, the Netherlands and Germany all face elections next year in which anti-mainstream and anti-immigration parties are gaining ground.
Relief, for now: Analysis by Katya Adler, BBC Europe Editor
The sigh of relief at the outcome of Austria's presidential election was very loud indeed in Brussels with most European leaders delighted that the EU and establishment-friendly, internationalist-minded Mr Van der Bellen will become president.
But voters in Austria - as across much of Europe and in the US - were divided. There weren't many percentage points between the presidential candidates. So there will be disappointment tonight, too, amongst those who support a more nationalist-minded, anti-globalisation, immigration-limiting point of view.
If we've learnt one thing from Brexit and the US elections, it's that voters are in an unpredictable mood. Anti-establishment sentiment is on the rise, but election victories for Europe's so-called populists are far from inevitable.
Opinion polls before Sunday's vote had suggested a tighter margin between the two rivals.
The election campaign was bitter - the candidates traded insults and some election posters were defaced.
Mr Hofer conceded within minutes of the first projections in this rerun.
He thanked supporters and described himself as "infinitely sad that it hasn't worked out". He called on all Austrians to work together, "regardless of how we cast our ballots".
Press sees Austria avoiding turmoil - BBC Monitoring:
Papers in Austria concentrate on the domestic fall-out of Alexander Van der Bellen's election.
The Kronen-Zeitung says voters rejected a "massive change of the political system", but it advises Mr Van der Bellen to seek "honest reconciliation".
Writing in Die Presse, Oliver Pink says "everything will stay the same" and that "Europe's interest in Austria will wane quickly".
But in Germany and France there is wider comment on what the result means for Europe.
Nikolas Busse argues in the Frankfurter Allgemeine Zeitung that Mr Van der Bellen's victory seems to rebut the "new domino theory" that one Western country after another will fall into the hands of right-wing populists.
Myriam Detruy, writing in Le Figaro, calls Mr Van der Bellen a "pro-European" whose election has made the possibility of an Austrian exit from the EU much more distant.
Mr Hofer had campaigned on an anti-immigration platform, amid anxiety in Austria following last year's huge influx of refugees.
He had also suggested Austria could follow Britain's vote to leave the EU with a referendum of its own, but later appeared to backtrack, suggesting instead changing the bloc into a purely economic association.
The leader of France's anti-immigration National Front (FN), Marine Le Pen, congratulated the Freedom Party on its campaign and looked forward to victory in Austria's parliamentary poll.
Nearly 6.5 million Austrians were eligible to vote.
Alexander Van der Bellen
- Age: 72
- Background: Economics professor
- Politics: Former Green Party leader
- On Trump: "His campaign style, the sexist attacks were unacceptable. As regards content he has raised concerns - let's give him several months"
- On immigration: "I want a liberal, cosmopolitan Austria. What I do object to is lifting the old borders"
- Age: 45
- Background: Aeronautical engineer
- Politics: Far-right Freedom Party
- On Trump: "I'm no Trump fan, but I do have high hopes of improved relations with Russia."
- On Germany's decision to open its doors to refugees: "I say we're not managing. It was a major mistake that has inflicted massive costs on the entire EU, as well as Austria and taxpayers."