WARSAW — Populists in Eastern Europe looked shaken on Monday, after local elections in Hungary dealt a blow to leader Viktor Orban and Poland’s ruling party lost control of the Senate.

Results in Hungary showed a clear win for the opposition in Budapest’s mayoral race and other victories over the ruling party in at least 10 of the country’s biggest 23 cities.

With 98 percent of ballot papers counted from Sunday’s elections, mayoral candidate Gergely Karácsony of the opposition had secured 51 percent of the vote, compared to 44 percent for the candidate from Orban’s Fidesz party.

Meanwhile, the final results from Poland’s elections on Sunday gave the right-wing Law and Justice party 235 seats in parliament. That constituted a majority, but not one substantial enough to push through constitutional changes.

Law and Justice also lost control of the upper house, which can delay and increase scrutiny when it comes to changes in the law, though it lacks the power to override them.

Poland and Hungary have both been called out by the European Union for eroding the independence of state institutions.

Both in the Senate elections in Poland and in the municipal vote in Hungary, opposition parties had rallied together to back a single candidate, in a strategy that appears to have paid dividends.

“It can be considered a turning point in Hungarian politics,” said Andras Biro-Nagy, director of Policy Solutions, a European research institute. “In the last nine years Fidesz seemed to be invincible, as Orban and his party won all nationwide elections. I think this might be the first crack in the system built by Orban.”

The strategy is seen as a test case for Hungary’s next general election in 2022.

After his victory, the new opposition mayor pledged to build a transparent, green and reputable city. He compared the race to the Istanbul elections in March, where the ruling party also suffered a humiliating loss.

The election was a major blow to Orban, the country’s four-term prime minister who has helped foster a new era of autocracy in the country.

Orban said he would “take note” of the result. “All we can say is that we are ready to cooperate in the interests of the people living in the country and in Budapest,” he said.

Orban’s party is also embroiled in a sex scandal, despite its efforts to position itself as a defender of conservative Christian family values. A prominent Fidesz mayor, Zsolt Borkai, refused to step down after the release of video footage that showed the married father of two participating in a cocaine-fueled orgy on a yacht.

“I think in many battleground cities this was the decisive factor in the last few days, and maybe in Budapest also,” said Biro-Nagy.

While the opposition in Poland unified around Senate candidates, analysts said the main opposition party’s parliamentary campaign was lacking. That the center-right Civic Platform managed to win 134 seats with such “poor leadership” is “incredible,” said Jaroslaw Kuisz, editor in chief of the online weekly Kultura Liberalna.

Observers from the Office for Democratic Institutions and Human Rights on Monday said that although the elections in Poland unfolded smoothly, they were marred by “intolerant rhetoric” and “bias in public media.” The ruling party has mobilized state media behind it.

Despite winning only a handful more seats under Poland’s complex voting system, the party gained 2 million extra voters after a campaign that focused on vilifying the LGBT community and promising to expand its popular social welfare program.

Law and Justice is likely to be disappointed in the overall results, said Kuisz, but pointed out the power of the Senate is not “huge” and that the party may be able to convince some senators to switch sides.

However, symbolically, “it’s highly important that one of the main organs in the process of legislation is lost,” he said.