Just months before pivotal elections that could reshape Turkey’s domestic and foreign policy, the government is spending billions of dollars in state funds to bolster President Recep Tayyip Erdogan and his governing party at the ballot box while unleashing an array of legal threats to weaken those who seek to unseat him.

Some economists call the spending spree unsustainable, and potentially harmful, as Mr. Erdogan tries to soften the blow of hyperinflation on Turkish families in the run-up to the vote.

Additionally, recent polls suggest that at least two potential opposition candidates could roundly beat Mr. Erdogan and one of them faces four legal challenges that could knock him out of the running and give Mr. Erdogan’s party control of Istanbul, Turkey’s largest city and home to one in five of the country’s eligible voters.

Mr. Erdogan and his aides insist that they are setting policy purely to serve the country of 84 million, whose citizens have rewarded him and his party with multiple electoral victories over the past two decades. His critics counter that he has used his many years as Turkey’s top politician to concentrate power in his own hands and is now using it to shape the outcome of the election before voters even go to the polls.

“Erdogan is trying to fight this battle on ground he chooses, under the framework that he determines, with the weapons that he picks, and preferably with the opponent that he prefers,” said Ahmet Kasim Han, a professor of international relations at Beykoz University in Istanbul.

Both Mr. Erdogan’s government and the political opposition view the simultaneous presidential and parliamentary elections as a momentous opportunity to set the future course for a NATO member with one of the world’s 20 largest economies and strong diplomatic and business ties across Africa, Asia and Europe.

Adding symbolism to the vote is timing. Mr. Erdogan has said it would be held on May 14, months before the 100th anniversary of the foundation of modern Turkey after the collapse of the Ottoman Empire.

In the meantime, he and his government have introduced vast spending for initiatives to insulate voters from the economy’s troubles, at least until the election.

Since late December, Mr. Erdogan has increased the national minimum wage by 55 percent; bolstered the salaries of civil servants by 30 percent; expanded a program to give subsidized loans to tradesmen and small businesses; and moved to abolish a minimum retirement age requirement, allowing more than 1.5 million Turks to immediately stop working and to collect their pensions.

Mr. Erdogan has said that if he wins, it would vindicate his efforts to build Turkey’s economy, increase its influence abroad and protect the country from domestic and international threats. Speaking to members of his Justice and Development Party, or A.K.P., in Parliament last week, he dismissed the political opposition as incompetent and billed himself as the best person to lead the country into its second 100 years, which he has called “Turkey’s century.”

“Look, here I am as a politician who solves problems in his region and the world, who takes responsibilities, who sets directions,” he said.

Mr. Erdogan has been Turkey’s paramount politician for two decades, as prime minister from 2003 to 2014 and as president since then. His first decade in power saw a drastic expansion of the economy that lifted millions of Turks out of poverty and expanded Turkish industry.

But in recent years, the economy has weakened and Turkish opponents and Western officials have accused Mr. Erdogan of pushing the country toward autocracy, largely because of sweeping powers he has granted himself since a narrow majority of voters passed a referendum in 2017 that expanded the president’s role.

Mr. Erdogan’s detractors say he has cowed the news media, limiting critical reporting, and extended his influence over the courts, leading to politically motivated trials. He has also taken charge of foreign and fiscal policy, sidelining the Foreign Ministry and the central bank.

A coalition of six parties have joined forces to try to unseat Mr. Erdogan and they say that if they win, they will restore the independence of government bodies and reduce the power of the president by returning to a parliamentary system.

“The election is not only about changing the government,” Canan Kaftancioglu, the Istanbul chairwoman of the largest opposition party, the Republican People’s Party, said in an recent interview. “It is between those who are in favor of democracy and those who are against democracy.”

Improving the opposition’s chances are the country’s economic troubles, which have caused some voters to question Mr. Erdogan’s stewardship. Largely because of his unorthodox financial policies, the national currency lost nearly two-thirds of its value against the dollar in the last two years and year-on-year inflation reached about 85 percent in November before dropping to 64 percent in December.

Turkey’s peak inflation rate in 2022 was nearly 10 times that of the United States and was the second-highest among the Group of 20 largest economies, after Argentina. Soaring prices have eaten into the budgets of Turkish families and eroded the middle class, damaging Mr. Erdogan’s popularity.

But the opposition faces major challenges, too.

Mr. Erdogan is a deft political operative and orator who can rely on a vast party apparatus that is enmeshed with the state and its resources. The opposition has yet to name its candidate, leaving Mr. Erdogan to campaign unopposed and fueling speculation that the opposition is plagued by internal divisions that could render it ineffective or tear it apart.

The recent government spending spree adds to other initiatives introduced last year: a cash support program for low-income families; government forgiveness of some debt; and state-funded accounts to protect local currency deposits from devaluation.

Many economists say this flood of state spending could buoy voters until the election, but will most likely fuel even higher inflation and could tip the country into recession sometime after the vote.

“The plan is, up until the election, they can spend lots of money,” said Ugur Gurses, a former central bank official and finance expert. “I think they think it is worth it if they are going to win. But if they lose, it will fall into the hands of the newcomers.”

The opposition’s position has been further complicating by new legal threats to Ekrem Imamoglu, the mayor of Istanbul and one of the potential rivals who recent polls suggest could beat Mr. Erdogan.

Last month, a court barred Mr. Imamoglu from politics for two years and seven months on charges that he insulted state officials. He had called electoral officials who overturned his initial victory in the 2019 Istanbul mayor’s race “fools.”

The race was rerun a few months later, and Mr. Imamoglu beat Mr. Erdogan’s candidate again, this time by a much larger margin.

Mr. Imamoglu remains in office while appealing the conviction. But in the weeks since last month’s court ruling, he has faced three new legal threats that could temporarily knock him out of politics and remove him from office, passing control of Turkey’s largest city to Mr. Erdogan.

The Interior Ministry has sued Mr. Imamoglu for alleged corruption during his previous job as an Istanbul district mayor in 2015; the interior minister has accused the mayor’s administration of employing more than 1,600 people with links to terrorism; and Mr. Imamoglu is being separately investigated for allegedly insulting another district mayor, who is a member of Mr. Erdogan’s party.

Hasan Sinar, an assistant professor of criminal law at Altinbas University in Istanbul, dismissed the legal threats as “purely political.”

“It’s all about Imamoglu because he’s the rising star of the opposition and they want to stop him,” said Mr. Sinar, who filed a legal brief in support of Mr. Imamoglu with the court in the first insult case.

While it was unclear whether Mr. Erdogan had personally intervened in the case, Mr. Sinar said he doubted that a judge would rule against such a high-profile figure without knowing that Mr. Erdogan would approve.

“This is a political act that looks like a legal one,” he said, “and no one can do this if it is against the will of the president.”

Safak Timur contributed reporting from Istanbul.