In elections that Americans may examine closely for parallels and to understand what is going on in Europe, Austria on Sunday elected a harmless Green Party candidate president over a less-harmless far-right candidate. The margin was excruciatingly close, just 30,000 votes.

The first round of voting last month eliminated candidates of the two main parties, the center-left Social Democrats and center-right People’s Party. They have ruled the Central European country of 8.6 million off and on since the end of World War II.

The two candidates remaining were Alexander Van der Bellen, former leader of the Green Party, and Norbert Hofer of the right-wing Freedom Party. Van der Bellen won with 50.3 percent of the vote, only after mail-in ballots were counted Monday.

Voters from the defeated centrist parties spared Austria the embarrassment of electing a far-right populist as head of state (though the nation’s chancellor is the more powerful political position). Hofer’s Freedom Party is anti-Muslim, likes Russian President Vladimir Putin, opposes migration and doesn’t like the European Union, which Austria joined in 1995.

It is likely that reaction to mainly Muslim migrants from the East are what helped the Freedom Party boost its vote so drastically, though there are only 90,000 or so asylum seekers remaining in Austria. The current government first followed German Chancellor Angela Merkel’s open-door policy. Then, in the face of opposition, it shifted to border closures and asylum quotas. And while the Austrian economy is relatively healthy and its citizens have a comfortable life, economic inequality is on the rise. A general sense of discontent contributed to the defeat of the old-guard centrist parties.

Europe watched these elections with some apprehension. Hungary and Poland already have right-wing governments. The Austrian election was a worrisome close shave.