VIENNA : Austria's Norbert Hofer narrowly failed Monday to become the EU's first far-right president after his ecologist rival scraped to victory in a knife-edge election that was a rude wake-up call for the continent's established parties.

Alexander Van der Bellen won 50.3 percent of the vote in Sunday's second-round, marginally ahead of 49.7 percent for Hofer, presented as the friendly and moderate face of the anti-immigration, populist Freedom Party (FPOe).

"Of course I am sad," Hofer said on Facebook as he conceded defeat, but added: "Please don't be disheartened. The effort in this election campaign is not wasted, but is an investment for the future."

Preliminary results late Sunday had put Hofer barely four points ahead in the runoff for the largely ceremonial but bitterly fought-over post of Austrian head of state.

But his paper-thin margin was erased after a record 700,000 postal ballots were counted during Monday, dramatically putting Van der Bellen ahead by just over 31,000 votes in the final tally.

Turnout was at almost 73 percent, high for European elections.

Most observers had thought that Van der Bellen, 72, an independent who stood with Green Party backing, would fail to beat his polished younger rival after lagging 14 points behind him in the first round on April 24.

"But in the last 14 days, there has been such a momentum among voters... (across) all sections of society," the professorial Van der Bellen said late Sunday.

Gun enthusiast Hofer, 45, had tapped into unease about the record number of asylum seekers at the height of Europe's migrant crisis, with his typical supporters made up of lesser-educated working-class men and in rural areas.

But the self-proclaimed "gladiator" has also toned down the FPOe's message to win voters across the spectrum disillusioned with the centrist parties in the current government that have dominated national politics since 1945.

His strategy mirrored the success of other fringe political figures across Europe, most recently in elections in Cyprus on Sunday, as well as further afield as seen with the success of Donald Trump in the United States.

In France, where the National Front's Marine Le Pen will run for president anext year, Prime Minister Manuel Valls voiced his "relief to see the Austrians reject populism and extremism... Everyone in Europe should learn from this."

Reinhard Buetikofer and Monica Frassoni, co-chairs of the European Green Party, said the message was that "Europe's values and our shared republican and democratic goals can be defended against insurgent right-wing populism."

But fringe politicians still drew solace from the result.

Frauke Petry, head of Alternative for Germany, who was in Vienna Sunday for what had been expected to be a victory party for the FPOe, congratulated Hofer for the "outstanding result".

France's National Front said the "historic performance is certainly the precursor of future success for all patriotic movements, both in Austria and around the world."

With 2.2 million Austrians voting for Hofer, Van der Bellen said Monday that he wanted to heal the rifts laid bare by the bruising election campaign.

"A lot of people in this country evidently feel that they aren't being seen or heard enough," he said after the result was announced, speaking in a tone that was anything but triumphant.

"We need a different culture of dialogue and a political system, which deals with people's fears and anger... I will also work toward winning the trust of Norbert Hofer's voters."

An even bigger challenge awaits the unhappy coalition government of the Social Democrats (SPOe) and the centre-right People's Party (OeVP).

They suffered a historic debacle in the first round the presidential election on April 24, knocked out with 11 percent each, and prompting chancellor Werner Faymann to quit.

His successor, Christian Kern of the SPOe, now has two years to win back voters from the FPOe - leading opinion polls under leader Heinz-Christian Strache - in time for the next general election, due in 2018.

Kern said Monday that the government "must remember that the election result was thanks to a worryingly close margin. Therefore it is of particular importance to us that... no voter feels like they have lost."