OROSZLÁNY, Hungary—Jabbing his finger at a life-size cardboard cutout of Hungarian Prime Minister Viktor Orbán , Péter Magyar wooed the voters of this coal-mining town with a feisty speech about corruption and economic decline.

Magyar, Orbán’s main rival in next year’s pivotal election, mocked him as a mafia boss, a Turkish sultan and Ali Baba with 40 thieves. He concluded with the Russian phrase “Tovarishchi, konetz” —or comrades, it’s over—the motto of the 1990 democratic election that ousted Hungary’s Soviet-installed regime.

“We will build a country where no one will suffer a disadvantage because of their political opinion,” said Magyar, a 44-year-old dressed in a hoodie and Adidas sneakers. “Where no one will be called a bug or a pest to be crushed just because they see the world differently.”

The Hungarian election, slated for April, is shaping up as the most competitive since Orbán, now 62, returned as prime minister in 2010 and grew into a global champion for traditional values , authoritarian politics and a beacon for the MAGA movement in the U.S.

In a diplomatic boost to Orbán, President Trump said Thursday he will hold his next summit with Russian leader Vladimir Putin in Budapest. “We love Viktor,” Trump quipped at a peace conference in Egypt days earlier, telling Orbán that he is endorsing him once again. “You are fantastic. I know that a lot of people don’t agree with me, but I am the only one that matters.”

Hungarian voters, of course, matter too. Several recent opinion polls predict that Magyar’s new Tisza Party, which won 29.6% of the votes in European Parliament elections in June last year, could secure a sweeping majority in April. To do so, it must reach beyond the liberal stronghold of Budapest and flip smaller towns like Oroszlány, where concrete housing blocks are still emblazoned with Communist-era murals.

The stakes are stark. Ever since the 2022 full-scale Russian invasion of Ukraine, Orbán’s Hungary has been at odds with the rest of the European Union and its North Atlantic Treaty Organization allies, blocking tougher sanctions against Moscow and hobbling military assistance to Kyiv. A frustrated Polish prime minister quipped this month that Orbán has joined Russia’s side in the conflict with the West. Orbán retorted that he is on the side of Hungary.

The Hungarian leader, who won the previous election in 2022 with promises to keep Hungary out of the war , is busy tarring Magyar as an agent of Ukrainian intelligence services. Orbán’s latest campaign video focuses on unproven allegations that a Ukrainian software company was involved in developing Tisza’s mobile-phone app. It featured an artificial-intelligence created deepfake of Ukrainian President Volodymyr Zelensky assuring in broken Hungarian that “all your data is safe with me in Kyiv” as an AI-generated Magyar clapped enthusiastically.

Ukraine has rejected accusations of meddling in Hungarian elections as absurd hysteria. Magyar, who said he would defend Hungary’s national interests if elected, dismissed the allegations as a sign of his opponent’s desperation.

His strategy has been to skirt around geopolitical matters to focus on one all-important issue: Orbán’s economic record.

Once one of Central Europe’s most prosperous and dynamic countries, Hungary has been overtaken by more competitive and investor-friendly neighbors over the past decade. As measured by actual individual consumption, an indicator of material welfare of households, Hungary last year for the first time became the poorest of the EU’s 27 member-states. The International Monetary Fund projects it to post growth of just 0.6% this year, with 4.5% consumer inflation.

“The key problem for Orbán is that for the last five years the Hungarian economy has been stagnating or in recession. The majority of the Hungarian people now believe that Orbán’s governance has been an obstacle to Hungary’s development,” said András Bíró-Nagy, director of the Policy Solutions think tank in Budapest. “Orbán has never had to fight an election in such unfavorable economic conditions.”

Magyar often speaks about corruption in Orbán’s government and among oligarchs close to it, zoning in on what he has described as a “Putin-style” luxury estate owned by the prime-minister’s family and promising to claw back stolen money once elected. Orbán has denied wrongdoing.

Unlike previous challengers, who came from the left and struggled to break through in the pro-Orbán heartland, Magyar is a relative conservative who hails from Orbán’s own Fidesz party and defies easy pigeonholing. His rise has all the hallmarks of a Shakespearean drama. In February last year, Magyar’s ex-wife, Judit Varga , resigned as justice minister along with Hungary’s largely ceremonial president, Katalin Novák , following leaks about their roles in pardoning a state orphanage executive implicated in a pedophilia scandal.

Magyar then broke with Orbán and launched his own political campaign. The following month, he released recordings he had made at home in which Varga complained of political pressure from Orbán’s office to intervene in a corruption case against a former government insider.

Now divorced, Varga has remained loyal to Orbán and accused Magyar of physical and emotional abuse, something he denies.

“He’s a traitor,” Orbán’s senior adviser Zoltán Kovács , the state secretary for international communications and relations, said about Magyar. “He’s unprincipled. There is a lack of respect for any kind of ideological or moral or any kind of stance. What matters to him is trying to come to power.”

Ágoston Mráz, chief executive of the pro-government Nézőpont Intézet think tank in Budapest, said that attacking Magyar’s personality isn’t working for the government because the challenger’s voters are primarily motivated by hostility to Orbán and don’t necessarily have much love for the opposition candidate anyway.

“It’s a very interesting political movement,” Mráz said. “His interest is only to talk about Mr. Orbán, to collect all the people who hate Mr. Orbán. But that doesn’t mean they would agree on policy issues with him.”

Indeed, when it comes to policy matters, Magyar has been deliberately short on specifics. Asked at the rally in Oroszlány, attended by several hundred locals, about how his government’s foreign policy would differ from Orbán’s, Magyar offered few details other than marking his distance from Moscow. Noting that Orbán talks often about the Hungarians’ historic homeland in the Urals, in today’s Russia, Magyar countered that the Hungarians have tied their fate to the West ever since King Stephen’s reign more than 1,000 years ago.

“The only way we can remain here in Central Europe, in safety and in peace, is by fulfilling our allied obligations,” he said. “We want to be respected and honorable members of our alliances.”

In Oroszlány, where the incumbent mayor and parliament member both belong to Fidesz, some locals said they are ready to switch their support to Magyar at the coming election. Their reasons had nothing to do with geopolitics.

Virág Varga, a factory operator and a mother of two young children, said she has been struggling to make ends meet since her husband died in 2021, leaving behind debts. “We gave Viktor Orbán a chance for 15 years. But now our salaries aren’t worth anything compared with the prices in the store. They’re completely exploiting us,” she said. As for Magyar, she said, “We don’t really know him yet, but we want to believe in him.”

Magyar’s promises to return to taxpayers the ill-gotten fortunes made by Orbán’s allies have won over retired nurse Sándorné File. “All this enrichment, it’s terrible, while everything here is falling apart, even the schools. And don’t even get me started on healthcare!” she said as she headed to Magyar’s rally as loudspeakers blared out “Can’t Stop the Feeling” by Justin Timberlake.

Support for Orbán, however, still runs strong in Oroszlány. János Cseri, a retired welder at the mine who is struggling with lung disease, said he has always voted for Fidesz and will do so again come April. “Magyar is not an honest man,” he said. “And if you look at the news, he’s got all kinds of connections with the Ukrainians. There might be something to it. We’re not saying it’s true, but it does make you wonder.” Several retired women and men sitting on a bench a few blocks away from the rally grew agitated at the very mention of Magyar, cursing loudly and wishing him death for daring to challenge Orbán.

Hungary’s electoral system features a combination of national lists and first-past-the-post constituencies, as well as a rule that allows mostly conservative ethnic Hungarians in nearby countries — but not the more liberal Hungarian expats living elsewhere—to vote by mail. Because of that structural disadvantage, Magyar’s Tisza would have to win by several percentage points nationwide in April to oust Orbán, electoral experts say.

The election campaign is likely to get much dirtier in coming months, and many opposition politicians fear that the system established by Orbán will do all it can to remain in power, or else run the risk of anticorruption trials and asset seizures.

Already, some are calling on people to prepare for mass protests like the Maidan Revolution in Ukraine, that ousted a pro-Russian leader in 2014, if there is any sign of election fraud.

“They will only be afraid of these protests if they last a long time and lots of people participate, paralyzing the country,” said Ákos Hadházy, an independent parliament member from Budapest. “The authorities are scared of only one word: Maidan.”

Write to Yaroslav Trofimov at yaroslav.trofimov@wsj.com