Alexander Van der Bellen has won Austria's presidential election, preventing Norbert Hofer from becoming the EU's first far-right head of state.
Hofer led narrowly after Sunday's election but postal votes counted on Monday gave Van der Bellen victory.
Van der Bellen campaigned on a pro-EU platform, backed by the Green Party.
Hofer, of the Freedom Party, tapped into anti-EU sentiment and fears about rising numbers of asylum seekers. He conceded victory on his Facebook page.
Hofer said it was a sad day and that he would have gladly served as president.
"But please don't be disheartened. The effort in this election campaign is not wasted, but is an investment for the future."
The official result is expected to be announced shortly.
Hofer had led Van der Bellen by 51.9% to 48.1%, the interior ministry said, after counting on Sunday.
But the 750,000 postal votes - roughly 12% of Austria's 6.4 million registered voters - swayed the result.
What was the breakdown of the vote?
In nine out of Austria's 10 main cities Van der Bellen came top, whereas Hofer dominated the rural areas, the Austrian broadcaster ORF reported (in German).
Support for Hofer was exceptionally strong among manual workers - nearly 90%. The vote for Van der Bellen was much stronger among people with a university degree or other higher education qualification.
Support for Hofer among men was 60%, while among women it was 60% for Van der Bellen.
What powers does the Austrian president have?
It is mostly a ceremonial post. But the president does have the power to dissolve the National Council - the more powerful lower house of parliament. That triggers a general election. The president can only do that once for a particular reason - he cannot use the same grounds to dissolve it again.
It is the chancellor's job to appoint government ministers. And the chancellor has the power to dismiss the government. But ministers have to be formally sworn in by the president. And Hofer has said he would not swear in a female minister who wore a hijab, which he has described as a sign of oppression.