PRAGUE — The two opposition alliances opposed to Czech Prime Minister Andrej Babis won a parliamentary majority Saturday, raising the possibility that Babis may be forced from office after an election shaken by financial disclosures in the Pandora Papers.

In a surprise surge, the center-right opposition alliance was narrowly ahead of the party led by Babis, a billionaire tycoon and ally of Hungary’s far-right leader Viktor Orban. A separate opposition bloc took parliament seats and would push the anti-Babis factions into the majority.

The Pandora Papers roared into the Czech elections in the final week, revealing that Babis allegedly used shell companies to purchase a $22 million French chateau in 2009.

“He definitely lost some voters because of this scandal,” said Jiri Pehe, director of New York University Prague. “I think the opposition alliances will be very united in their efforts to force Babis out.”

Addressing his supporters, center-right opposition leader Petr Fiala ruled out a coalition with Babis’s party and said “the result of this election is a victory of decency and moral values.”

The outcome is likely to be closely watched in Hungary, where opposition factions are trying to unify before elections next year that will test the strength of Orban and his hard-line policies that include anti-migrant laws.

But the effort to remove Babis could become lengthy and fraught with potential obstacles.

Czech President Milos Zeman — a Babis ally — had previously suggested that he may still appoint Babis as prime minister, even if he does not hold a parliamentary majority.

The president’s rationale: Babis’s political base is composed of one party, while the opposition formed two alliances of several parties. Zeman could argue that Babis is still the head of the country’s largest party, even though he came in second.

“In the next days, weeks, months, the key player will be president Zeman,” said Filip Kostelka, a political researcher at the University of Essex.

In a post-election speech, Babis conceded that the center-right opposition alliance had won, but he also called the concept of alliances “a scam.”

“We’ll see what the president will say,” Babis said.

Speaking on Czech television, political analyst Tomas Lebeda warned that if the president “doesn’t appoint Mr. Fiala as the prime minister, the country will plunge into a deep constitutional crisis.”

Babis was the first major elected official named in the Pandora Papers to face voters.

The Pandora Papers — published by The Washington Post and other media outlets around the world — expose vast reaches of the secretive offshore system used to hide billions of dollars from tax authorities, creditors, criminal investigators and — in 14 cases involving current country leaders — citizens around the world.

The revelations include more than $100 million spent by King Abdullah II of Jordan on luxury homes in Malibu, Calif., and other locations; millions of dollars in property and cash secretly owned by Babis and the leaders of four African nations; and a waterfront home in Monaco acquired by a Russian woman who gained considerable wealth after she reportedly had a child with Russian President Vladimir Putin.

As voters headed to the polls in the Czech Republic’s two-day election, the revelations were a hot topic for both Babis’s backers and foes.

“Babis is a criminal and a great manipulator,” said Jiri Hladky, 60, who supported the center-right.

But in Bohnice, a district in the north of Prague, many defended Babis — and described the Pandora Papers as political misinformation created by the Czech opposition.

“Maybe some of it is true, but for me it’s not important,” said Jiri, 71, a Babis voter who spoke on the condition that his last name not be used, citing privacy concerns.

“It’s dirty play,” agreed pensioner Marie Hajkova, 64, also a Babis voter.

After coming to power, Babis increased state payments to pensioners and disadvantaged families. The country’s budget deficit ballooned to record levels. But in Bohnice and many other parts of the country, the payments have helped Babis to form a loyal base of supporters.

“He has done more for me than any other candidate in the history of this country,” said Hajkova, citing an increase in her pension payments after he came into office.

Most of Babis’s core voters remained loyal to him in this election, but his hopes to remain in office also rested on the performance of smaller parties that might have been willing to support him in a coalition.

Those parties, however, performed weaker than some had expected, and several failed to get into parliament.

The Pandora Papers were “another piece of the puzzle,” said Ivan Bartos, the head of the Czech Pirate Party, which would play a key role in a government formed by the two main opposition alliances.

Speaking to The Post before the votes were fully counted, he warned that a second Babis term may lead to the “Orbanization” of the country and “probably steps that would somehow exclude us from the democratic Europe as we know it right now.”

“That’s the path we don’t want to go through,” he said.