Mr. Erdogan has also pushed Turkey into a more active role in the Middle East, presenting the country, with its growing economy and mix of Islamic and democratic credentials, as a model for an Arab world in turmoil. In practice, though, he has few foreign policy successes to point to. Turkey’s support of the Muslim Brotherhood in Egypt ended with the Islamist group’s president, Mohamed Morsi, being ousted by the military and hundreds of his supporters killed.

Mr. Erdogan was an early supporter of the Syrian rebels fighting President Bashar al-Assad, a policy that now seems to have been a bad miscalculation, as analysts and foreign powers blame Turkey, partly, for the rise of the extremist Islamic State in Iraq and Syria. Turkey’s formerly lax border policies, analysts say, allowed ISIS to flourish and move men and guns into Syria.

Turkey, a NATO member, has long been a strategic ally of the United States. At the outset of the Arab Spring revolutions, in 2011, President Obama developed a close personal relationship with Mr. Erdogan, seeing Turkey as a model to emulate for countries upended by revolution.

But the relationship has lately been badly damaged over differences on Egypt and Syria. It took another blow when Mr. Erdogan suggested that a conspiracy involving the United States was behind a wide-ranging corruption investigation that targeted him and his inner circle. Mr. Erdogan has blamed the followers of Fethullah Gulen, a popular cleric in self-imposed exile in the United States whose supporters occupy positions in Turkey’s police and judiciary, for the corruption probe, and demanded that the United States extradite Mr. Gulen.

Nowadays, Mr. Erdogan no longer speaks directly to Mr. Obama, he said.

“Why did the U.S. remain silent when a popularly elected Morsi was ousted in a military coup?” Mr. Erdogan said in the interview. “Why did the West remain silent? And so, they also asked us to remain silent. When we called it a military coup, they looked at us in a wrong way, and there, ties were cut. We will, however, continue to say the same thing.”

Mr. Erdogan’s rule has come at the cost of deep polarization in Turkish society.

The public is divided almost exactly in half between those who support Mr. Erdogan and his Islamist Justice and Development Party, and others who despise him for what they regard as his authoritarian streak. His opponents, though, are also sharply divided, between nationalists, those loyal to the secular principles of Ataturk, and more liberal, urban Turks who formed the backbone of a protest movement that convulsed the streets of Istanbul and other cities last summer. Two candidates are running against Mr. Erdogan: Ekmeleddin Ihsanoglu, a former diplomat, and Selahattin Demirtas, the candidate of a pro-Kurdish party.

But neither of these candidates has been able to unite the various factions among Mr. Erdogan’s opponents, and so Mr. Erdogan is almost certain to win in the voting this Sunday. If he does not receive at least 50 percent of the votes on Sunday, the election would go to another round, on Aug. 24, between the top two finishers.