For a decade and a half, President Recep Tayyip Erdogan of Turkey has increasingly governed as a strongman, first as prime minister and then, since 2014, as head of state. In that time, he has transformed the country into a diplomatic heavyweight in the Middle East, while eroding much of its internal democratic infrastructure.
In the international arena, Turkey has become a major actor in the Syrian war, a crucial player in the attempts to curb the European migration crisis and an unreliable ally to the United States and in the North Atlantic Treaty Organization.
After an attempted coup, Mr. Erdogan has jailed tens of thousands of opponents, fired or suspended more than 100,000 people from their state jobs and turned Turkey into the biggest jailer of journalists in the world.
On Sunday, Turks headed to the polls to elect both a new president and Parliament, in an election that will give the country’s next president sweeping new executive powers. Two months ago, Mr. Erdogan appeared to have both votes locked up. But thanks to a tanking economy and an unexpectedly spirited performance by the opposition, the race is proving tighter than expected, both for him and his Justice and Development Party.
Mr. Erdogan has been mainly a ceremonial head of state — exerting his will on Turkey through force of personality rather than constitutional right. But if he retakes the presidency, he will be formally granted broad new executive powers, effectively codifying into law the authoritarian way in which he has informally governed up to now.
With Sunday’s election, Turkey will transform from a parliamentary democracy into a presidential one, thanks to a constitutional referendum that passed narrowly last year amid accusations of vote rigging.
The new system will abolish the post of prime minister and transfer executive power to the president, giving the newly empowered president the right to issue decrees and to exert far greater influence over the judiciary and the Civil Service.
The new version of the Parliament will have some ability to curb the president’s actions. But if Mr. Erdogan and the Justice and Development Party win both the presidential and parliamentary elections, power will be centralized around Mr. Erdogan in a manner not previously known in Turkey’s democratic history.
“We’re moving in full force into a new system — some would call it a new regime,” said Soli Ozel, an international relations professor at Kadir Has University in Istanbul.
Turkey has been under a state of emergency for almost two years, since a failed coup against Mr. Erdogan in July 2016. And that has allowed the government to tilt the playing field in his favor.
One presidential candidate — Selahattin Demirtas, of the pro-Kurdish opposition group, the Peoples’ Democratic Party — has had to run his campaign from jail. He has been imprisoned on politicized charges for nearly two years, along with several of his lawmakers and dozens of his party’s local officials.
Under the state of emergency, political intimidation has become routine, government opponents have been accused of terrorism, and press freedom and the right to protest have been significantly curtailed.
Pro-government companies own 90 percent of the news media, allowing Mr. Erdogan hundreds more hours of television time than most of his opponents.
Mr. Erdogan’s main challenger is Muharrem Ince, a fiery former physics teacher from the Republican People’s Party, a centrist and secularist political grouping that has historically seemed removed from the struggles of ordinary people in Turkey’s rural heartlands.
Mr. Ince is polling at just below 30 percent, some 20 percentage points behind Mr. Erdogan but 20 ahead of the next two challengers, Meral Aksener and Mr. Demirtas.
Mr. Erdogan has historically maintained his popularity in two main ways.
The first was by championing Turkey’s pious majority, who felt marginalized by the secular-leaning elites who ruled the country for much of the 20th century. The other was his transformation of a struggling economy into a strong one.
But with the value of the Turkish lira in free fall and with food prices rocketing, Mr. Erdogan’s reputation as the guardian of the economy is much diminished.
That has made for a tighter race than analysts expected — as has Mr. Erdogan’s comparatively lackluster performance on the campaign trail.
After Mr. Erdogan oddly promised voters free cake at new government-run cafes, his opponent Mr. Ince quipped: “He says you will eat cake there for free. I, on the other hand, am telling you that I will find jobs for our children.”
The opposition has also put up a more coordinated fight. The mild-mannered leader of the Republican People’s Party stepped aside to allow his feistier colleague, Mr. Ince, to run.
The presidential race could be close if Mr. Erdogan does not win more than 50 percent of the vote in the first round, which would prompt a second round, on July 8.
If that happens, most of the main opposition candidates have indicated that they will rally round his remaining challenger, who might have enough support for a narrow victory.
Last year’s constitutional referendum was marred by accusations of widespread voter fraud. The opposition fears a repeat on Sunday — particularly after the government introduced a new electoral law that will allow counters to accept ballots that have not been marked by an official stamp. The law will also give government employees greater freedom to decide which ballots can be accepted.
The Justice and Development Party has said that the vote will be free and fair, and that fraud claims will be investigated.
“We have by now taken every measure about security,” Mr. Erdogan said of the voting procedures at a rally in Istanbul on Saturday.
But Mr. Erdogan has exacerbated fears that the vote may be rigged. In a leaked video, he seems to tell party colleagues to ensure the Justice and Development Party has a majority presence on monitoring committees at polling stations to “finish the job in Istanbul before it has even started.”
The main areas to watch will be the ones heavily populated by Kurds in eastern Turkey, where the result will be critical to deciding whether Mr. Erdogan will get a majority in Parliament.
The polls opened at 8 a.m. and closed at 5 p.m. (10 a.m. Eastern), and the presidential election results will be announced first. The results are expected to start coming in about 9 p.m. in Turkey.
The opposition has warned that Mr. Erdogan may announce his victory while the ballots are still being opened.