Austria President-elect Alexander Van der Bellen
Independent candidate Alexander Van der Bellen smiles in Vienna after narrowly winning the Austrian presidential election, Monday, May 23, 2016. REUTERS/Leonhard Foeger

Austria narrowly avoided Monday becoming the first European Union country to elect a far-right candidate as head of state, as postal ballots decided a knife-edge presidential runoff vote in favor of his environmentalist rival.

After an election that had been too close to call on Sunday, a count of the absentee votes on Monday put the 72-year-old Alexander van der Bellen just past anti-immigration Freedom Party rival Norbert Hofer and into the largely ceremonial post of president.

The final Interior Ministry count gave van der Bellen 50.3 percent of the vote, against 49.7 percent for 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.

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, while the country's traditional ruling parties, which were humiliated and shut out in the furst round of the election, breathed a sigh of relief.

"Fifty percent confidence in Norbert Hofer is a gigantic showing," Hofer's campaign manager Herbert Kickl told public broadcaster ORF, toning down comments before the election that suggested the Freedom Party (FPO) 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."

"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, long-ruling coalition of two centrist parties, the Socialist and Peoples parties. Opinion polls regularly suggest the Freedom Party would win parliamentary elections if held now. The current government's term runs until 2018.

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."

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 in a Twitter post. "Everyone in Europe must draw lessons from this."

Prosperous Austria has been at the center of a record influx of migrants, fanning resentment towards the Social Democrats (SPO) and the conservative People's Party, which have dominated politics since the end of World War II.

Sunday's provisional result, which did not include the postal ballots, had shown Hofer ahead.

But the SORA institute, a pollster, said that mail-in ballots were likely to favor former Greens leader van der Bellen 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 neighboring 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. Across the English Channel, the UK Independence Party is campaigning for Britain to leave the European Union in a referendum on June 23.

"Despite the disappointment, a historic score for our ally from the FPO," French National Front Secretary General Nicolas Bay said on Twitter. "The future belongs to patriots!"

Hofer, 45, has described himself as a center-right politician and told voters not to believe suggestions from other parties that he would be a dangerous president.