HODMEZOVASARHELY, Hungary — Even by the standards of a country that has swung hard toward one-party rule, this small city on the fertile plains of southern Hungary is a pro-government stronghold.

Or so it seemed.

Then came the city’s mayoral election, when all expectations were upended. Faced with a likely rout by the Fidesz party of Prime Minister Viktor Orban, the long-feuding opposition parties banded together and put forward a single candidate. 

A month later, he sat triumphant in his classical-art-filled city hall office and said there’s no reason his victory can’t be replicated in the April 8 parliamentary elections, seen by Orban’s critics as a make-or-break moment for Hungarian democracy.

Hungary is in the midst of a divisive election that will decide if the country’s anti-immigrant prime minister gets a third straight term in office. (Griff Witte, Jason Aldag/The Washington Post)

“The story of this town can be a parable for the country,” said the newly elected mayor, Peter Marki-Zay. “If there’s an alliance of opposition voters, the people against dictatorship, then there’s hope. And if there’s hope, turnout will be high and Fidesz will be defeated.”

But with just weeks to go before the elections, the sort of coordination on display in Hodmezovasarhely remains elusive elsewhere in Hungary. 

The opposition parties may agree that Orban represents a grave threat to civil society, rule of law and free expression less than three decades after Hungary threw off the chains of communism. But they can’t agree on a strategy for stopping him.

The fractured nature of the opposition leaves a clear path for Orban to claim a third consecutive landslide victory and consolidate control in a country where his party faces diminishing obstacles to absolute power. 

“The opposition parties are still acting like they don’t understand what’s at stake,” said Marton ­Gulyas, who has been trying to encourage them to cooperate through his grass-roots Country for All movement, to little avail. “Another Fidesz majority would be a disaster for the country. But there’s still no strong and recognizable alternative for those who are fed up with Fidesz.”

Polls show Fidesz winning about 50 percent of the vote nationwide. The rest of this country of 10 million is split among four main opposition parties, none of which polls higher than the teens. 

Under Hungary’s complex electoral system, half the vote for ­Fidesz could be good enough for a two-thirds majority in the National Assembly — wide enough to pass virtually any legislation, including changes to the constitution. Fidesz has promised a law that civil society groups have said would severely limit their ability to operate.

Critics say Fidesz has already used its overwhelming majority from the past eight years to tilt the electoral playing field decisively in its favor, gerrymandering districts and commandeering supposedly independent offices of government, along with much of the media.

The opposition parties could still offer a serious challenge on April 8 by teaming up and agreeing on a single candidate in each of the country’s 106 electoral districts. Such a deal could be negotiated right up until the final day before the vote. 

Doing so, however, would require the parties to put aside ideological differences, personal mistrust and powerful financial incentives to keep all their candidates on the ballot. (Parties receive funds based on the number of votes they receive.)

On the surface, at least, the ideological divisions alone would seem insurmountable. The two largest opposition parties come from opposite sides of the political spectrum — the far-right Jobbik party and the left-of-center Socialists.

Jobbik has a toxic reputation in mainstream European political circles, owing to a history of anti-Semitic and racist remarks by its leaders. 

But as Orban has steered Fidesz to the far right — his pitch for reelection centers on warnings of the coming “Muslim invasion” and denunciations of the Hungarian American financier and philanthropist George Soros — Jobbik has shopped for new political real estate. 

“We gave Viktor Orban a lot of his ideas,” said Marton Gyongyosi, Jobbik’s foreign policy point man.

Rather than tack further right, the party has tried to stake out ground in the center, apologizing for its prejudicial past and even moving toward the left by emphasizing calls for economic justice and equal pay.

The conversion would seem to make possible what was once unthinkable: cooperation between Jobbik and three smaller left-of-center parties, including the Socialists. 

Gyongyosi said there was appetite, in theory, to team up against the common enemy of Orban. But he also said Jobbik was wary of associating itself with the Socialists, a party that has not recovered from the taint of corruption acquired during eight years in power before being tossed out by voters in 2010.

The ambivalence goes both ways, a reality on display during a desultory rally of a few thousand Socialist voters and their allies in Budapest for the country’s independence day last week.

“Jobbik is not part of the solution. They’re part of the problem,” Agnes Kunhalmi, a Socialist lawmaker from Budapest, told the crowd gathered in front of the city’s famed Freedom Bridge. 

Minutes later, she was contradicted by the party’s own candidate for prime minister, Gergely Karacsony, who said he would reluctantly do a deal with Jobbik if it meant a better chance at defeating Orban. 

“We have to cooperate with everyone, even with the devil,” he said. 

The rally’s relatively sparse crowd stood in contrast to the masses of supporters mustered by Fidesz, which gathered well over 100,000 people outside the parliament for its own independence day rally. 

In his speech, Orban barely mentioned the opposition except to call it “anemic”; he trained his fire instead on Soros and other supposed agents of foreign influence. 

The rally was an important show of strength for Fidesz after the humiliation of the mayoral vote in Hodmezovasarhely last month.

The city of 45,000, which was Hungary’s fourth largest in the late 19th century and still boasts grand public buildings from a long-gone era of affluence, had been considered a rock-solid Fidesz bastion. One of Orban’s top lieutenants, Janos Lazar, was once the mayor, and he remains the preeminent local power broker.

But Marki-Zay’s successful insurgent candidacy showed that ­Fidesz support may be softer than it appears. 

An economist and father of seven children, the 45-year-old had been a Fidesz supporter himself, and had never run for office. But he said he grew disenchanted with what he described as the party’s corruption and cronyism. 

Apparently he wasn’t the only one. On election day, a record 62 percent of eligible voters cast ballots, and Marki-Zay defeated the heavily favored Fidesz candidate by 16 points.

“People are not happy in this city — or in the country,” he said. “They’re tired of the intimidation and the corruption.”

Or perhaps a more prosaic explanation was at work, but one equally worrisome for Fidesz. People could simply be ready for a change.

“Everyone deserves a chance,” said Ferencne Kiss, an 82-year-old retiree, as she strolled the city’s quiet lanes. “We’ve been under ­Fidesz rule for some time now. Let’s see what the new guy can do.”

Gergo Saling contributed to this report.