PRAGUE — In a blow to Europe’s once surging populist politicians, the prime minister of the Czech Republic, a pugnacious businessman who has compared himself to Donald Trump and railed against migrants, suffered a surprising defeat in a parliamentary election that ended on Sunday.
After two days of voting, near-final results indicated that a center-right coalition of parties led by a button-down former academic had won the largest share of votes, narrowly ahead of a party led by the scandal-singed prime minister, Andrej Babis.
Czech Television calculated that opposition groups would win 108 of 200 seats in the lower house of Parliament, meaning that Mr. Babis, a billionaire, had little chance of staying on as prime minister.
The results, which showed a nationalist party led by a Czech-Japanese firebrand getting around 9.6 percent of the vote, were far from an unequivocal rejection of far-right populism. But the strong showing by the mainstream coalition and a socially liberal opposition group, the Pirates, allied with another party dominated by local mayors, suggested that a populist wave in Eastern and Central Europe is perhaps receding.
That wave, lifted though not created by Mr. Trump’s surprising 2016 election victory, has lost much of its momentum of late, stalled by the growing unity of its previously squabbling opponents and a crisis of confidence among European nationalists created by Mr. Trump’s defeat last November.
Mr. Babis, speaking on television late Sunday, insisted that his party, ANO, had a “great result” given that “there were 5 parties against us with only one program — to take down Babis.” But he conceded that “we did not expect to lose,” blaming the defeat on Prague, the capital, where voters are generally far more liberal than elsewhere in the country.
Members of the victorious center-right coalition, Together, were exultant over their unexpected, albeit very small, win: 27.8 percent of the vote for them versus 27.13 percent for Mr. Babis’s party.
At the coalition’s headquarters in central Prague, one of its candidates, Hayato Okamura, the older brother of the nationalist leader Tomio Okamura, rejoiced at his own camp’s success. He called it “God’s will,” saying that as a devout Christian, he had been praying for days that his brother and what he described as “far-right extremists” would not prevail. “They do not belong in a decent government,” he said.
The Czech vote will be disquieting news for the Hungarian leader Viktor Orban, the self-declared standard-bearer of “illiberal democracy,” whose Fidesz party faces elections next year and could well lose if its fractious opponents stick to pledges to form a united front.
Slovenia’s prime minister, Janez Jansa, a close ally of Mr. Orban and like-minded scourge of liberal elites, whom he calls communists, has also struggled, with his party’s approval rating slumping in opinion polls.
The Czech vote was so close that it will likely lead to a long period of haggling as different groups try to form a government. The president, Milos Zeman, who is gravely ill and partial to Mr. Babis, could ask the defeated prime minister to form a government as leader of the single party with the most votes in the election. But opposition groups, which together won more seats in Parliament, will likely torpedo any attempt by Mr. Zeman to keep Mr. Babis in power.
Mr. Babis, the Czech Republic’s bruised prime minister, long stood apart from the often vicious, anti-immigrant language deployed by the leaders of Hungary, Slovenia and also Poland, led Law and Justice, a deeply conservative and nationalist party. But, in an effort to mobilize voters before polling stations opened on Friday, he adopted the anti-immigrant theme with gusto.
With Mr. Orban as his guide, Mr. Babis in late September visited a border fence built by Hungary in 2015 to keep out asylum seekers from war zones and economic migrants trying to enter from Serbia. A few days later, Mr. Orban visited the Czech Republic, saying that “Hungarians would be happy to have such a great prime minister like Babis.”
Mr. Babis’s election campaign featured pledges to “fight until my dying breath” against immigration, and also against ice-cream made with foreign milk.
“He succeeded in making migration one of the main issues of the election, but anti-immigrant talk wasn’t enough; he lost,” Otto Eibl, the head of the political science department at Masaryk University in Brno, the Czech Republic’s second-most populous city, said in a telephone interview.
The election, he added, did not revolve around policy choices but “was a referendum on Andrej Babis.”
Neither the opposition coalition nor Mr. Babis won an outright majority of seats, but a small party on which Mr. Babis had previously relied to form a government failed to win any seats, opening the way for his rivals to stitch together a majority in the legislature.
“People were fed up with the populist, short-term politics of Andrej Babis,” said Petr Fiala, a former political scientist and university rector who led the anti-Babis coalition and is now best placed to become prime minister. “We want to do normal, competent and decent politics and people have believed in us.”
“The change we have promised is here. And we will make it happen,” Mr. Fiala added, speaking on television as the last votes were being counted.
To do that, however, he needs to form an alliance with the Pirates, an anti-establishment party that supports gay marriage and other progressive causes, something that many of Mr. Fiala’s more conservative followers reject.
The results, while far from a decisive victory for the opposition, delivered an unexpected rebuke to Mr. Babis, a tycoon who has dominated the Czech political scene for nearly a decade, mixing right-wing populist rhetoric with traditionally left-wing policies like pension increases and support for the disadvantaged.
The Czech Republic’s fourth wealthiest businessman, Mr. Babis first entered politics in 2011 and, prefiguring Mr. Trump’s cry of “drain the swamp” adopted the slogan of “end the political morass.”
But he has since been swamped by a series of scandals involving funding from the European Union, accusations that he collaborated with communist-era intelligence services, and the purchase, through offshore shell companies, of a villa and other properties on the French Riviera worth more than $20 million.
His opaque property deals became known during the last days of the election campaign thanks to a documents released by the International Consortium of Investigative Journalists.
The documents, known as the Pandora Papers, exposed how the rich and powerful, particularly politicians, use offshore structures to hide their wealth. The shuffling of funds through opaque shell companies is not necessarily illegal and Mr. Babis, who had not entered politics when he bought his French properties, dismissed the papers as a political hit commissioned by a left-wing “mafia” comprising his enemies.
Mr. Eibl said the revelations had probably played an insignificant role in the election, noting that few people voted for Mr. Babis because they believed he was clean. A recent survey of his supporters found that only 22 percent think he is honest.
“Of course he is not 100 percent clean, but he is no worse than all our other politicians,” said Vera Hrdlickova on Sunday after casting her vote for Mr. Babis’s party at a polling station in Prague.
Pavla Holcova, a Czech journalist who worked with the journalists consortium on the Pandora Papers, dismissed as absurd claims last week by Mr. Babis that the documents about his property dealings had been released to damage his chances. “Andrej Babis is not such an important global figure that 600 international journalists decided on the timing in order to hurt him,” she said.
Most, she added, had never heard of Mr. Babis.
Barbora Petrova contributed reporting.