Austria came close to becoming the first EU country to elect a far-right head of state, as a knife-edge presidential vote narrowly elected a pro-EU independent.
Alexander Van der Bellen, a former Greens party leader, beat anti-immigration Freedom Party rival Norbert Hofer by just 31,000 votes among the 4.64 million cast.
The election had been too close to call on Sunday until a count of absentee votes the following day thrust the 72-year-old past Mr Hofer and into the largely ceremonial post of president.
The president-elect vowed to address the "divisions" among Austrians that the poll had "made visible".
Mr Hofer's campaign had targeted anti-EU feelings and fears about migrants. He said his defeat was a "sad day". The Freedom Party candidate said on his Facebook page: "Please don't be disheartened. The effort in this election campaign is not wasted, but is an investment for the future."
The interior ministry said Mr Van der Bellen had won 2,254,484 votes to Mr Hofer's 2,223,458, or 50.3 percent to 49.7 percent.
Although Mr Van der Bellen is officially independent, he led Austria's Greens for a decade and some European Green politicians were hailing him as the world's first elected Green head of state.
Speaking after his victory, he said he accepted many Austrians had different views and that some people were angry, but he added: "People can be different and still treat each other respectfully."
The rhetoric in the campaign had been fierce at times. Mr Van der Bellen had said he did not want Austria to be led by a "populist right-wing, pan-Germanic fraternity member" and even urged voters "who don't like me but perhaps like Hofer even less to vote for me".
Mr Hofer had been photographed sporting the German colours of the nationalist Marko-Germania student fraternity, which stands for "the German cultural community" and bears the slogan "Honour, Freedom, Fatherland".
At his swearing-in as Freedom Party candidate, Mr Hofer wore a cornflower in his lapel, which was a Nazi symbol in the 1930s.
Mr Van der Bellen is the first environmental activist to become Austrian president. He is the son of aristocratic refugees from Russia's 1917 Bolshevik Revolution. First they escaped from Pskov to Estonia, then in 1940 they fled the Soviet occupation - the communist takeover of the Baltic states.
The family settled in Austria's Tyrol region. Alexander grew up in Kaunertal and does not speak Russian. His surname harks back to Dutch ancestry.
He studied economics at the University of Innsbruck and was later appointed professor at Vienna University. He retired from academia in 2009.
He was elected to parliament for the Greens in 1994, and from 1997-2008 was the party's spokesman.
In a TV debate, one of the few things he agreed on with Mr Hofer was that neither would accept TTIP - the free trade deal the EU is negotiating with the US.
-BBC / Reuters