ISTANBUL — It was bad enough for President Recep Tayyip Erdogan of Turkey that his chosen candidate lost again in a do-over election for mayor of Istanbul. But as the scale of the defeat became clear on Monday, Mr. Erdogan and his strongman methods faced recriminations not just from critics, but from his party and wider circle of supporters.
Not only did more people vote in the repeat election on Sunday, but they gave the opposition candidate the kind of endorsement that indicated a desertion from the governing Justice and Development Party, the A.K.P., and even from Mr. Erdogan himself.
The result fractured the invincibility of a strong-willed leader with little tolerance for dissent, who has made Turkey an increasingly prominent force in the Middle East and raised tensions with the United States as he moves his country, a member of NATO, closer to Russia.
“Earthquake at the ballot box,” ran the front-page headline of Karar, a newspaper founded three years ago by journalists who had once been close to the A.K.P. government.
“The margin is a reaction against the unfairness and the recklessness of doing politics with the disproportional state power, as much as it is the electorate’s loyalty to democracy and law,” Mustafa Karaalioglu, a columnist, wrote in Karar. “The electorate rose against those who did not understand what it had told them. The ballot box this time did not talk, but shouted.”
Preliminary results announced Monday by Sadi Guven, head of the High Election Council, showed that the opposition candidate, Ekrem Imamoglu, won 54 percent in the repeat vote for mayor of Istanbul; Mr. Erdogan’s candidate, Binali Yildirim, received 45 percent of the vote.
Mr. Imamoglu won by more than 800,000 votes, compared with a 13,000-vote victory in the first ballot. Turnout rose one percentage point, to 84 percent.
Mr. Erdogan will now have his hands full in containing the fallout from the electoral defeat, the biggest of his political career, which came after what in hindsight was his disastrous decision to push for a rerun of the mayoral election after Mr. Imamoglu’s initial victory three months ago.
It was hard to overstate the sting for Mr. Erdogan. Istanbul is his hometown, and the A.K.P. has dominated the city for 25 years, since he became mayor in 1994.
“Slap of the people,” Evrensel, a leftist newspaper that is frequently critical of Mr. Erdogan, announced on its front page. “Istanbul made its choice,” ran the headlines in three main pro-government newspapers.
Complaints had already been building within Mr. Erdogan’s party after its loss in the March election and the subsequent cancellation of that vote.
Several analysts, including some who have worked with Mr. Erdogan and others who ran the campaign against him, said that the defeat showed deep problems within his camp, which could cost him the presidency when he faces re-election in four years.
Ozgur Unluhisarcikli, the Ankara director for the German Marshall Fund of the United States, a research organization, said “the scale of the result represents a sociological shift” away from the A.K.P. and toward the opposition.
Some said Mr. Erdogan was likely to take a lower profile domestically in the immediate aftermath of the defeat, as he planned his way forward.
The largest challenge for Mr. Erdogan is a movement led by a former A.K.P. president, Abdullah Gul, and a former finance minister, Ali Babacan, to form a breakaway party. Both men support many of the ideals of the A.K.P., notably conservative pro-market policies with social support for the party’s lower-income political base.
Mr. Erdogan is likely to seek some changes, partly to weaken any challenge from the breakaway group, but that could destabilize his alliance with the Nationalist Movement Party, which he has relied on to secure the presidency and a majority in Parliament.
“The big question is: Will he ultimately stick to the ultranationalist alliance and continue the paranoid security state or reverse course and attempt at reform?” said Asli Aydintasbas, a senior fellow with the European Council on Foreign Relations.
While the Istanbul mayor’s race may seem relatively unimportant, the consequences for Mr. Erdogan are far-reaching, because his party has relied on financing from supporters in the business world and companies that have benefited from government contracts.
Now, not only has Mr. Erdogan lost access to that source, but Mr. Imamoglu will have access to records that seem likely to detail potentially embarrassing cronyism and wasteful spending that have benefited the president’s supporters.
Mr. Imamoglu got a foretaste during the 17 days he spent in office before he was forced to step aside during the election rerun. In that time, he discovered that Istanbul, Turkey’s economic capital, had dozens of cars at the mayor’s disposal and millions budgeted for officials’ homes, even as the city was sinking into debt.
In addition, the Istanbul municipality paid millions of dollars to charitable foundations run by Mr. Erdogan’s family last year, Turkish newspapers have reported.
Pro-government newspaper columnists are already moving to divert the mood, writing that Mr. Erdogan would turn to foreign policy to enhance his image. That suggested that far from tempering his stance, the president may project a more combative attitude in discussions abroad.
The pro-government newspaper, Aksam, made Turkey’s dispute with the United States over its purchase of the Russian S400 missile system the lead story, with a headline that read “S400s a matter of sovereignty.”
“Today the most common feeling among the people is the betrayal by their historical allies, the U.S., France, the U.K. and Germany,” Hakki Ocal wrote in the pro-government Daily Sabah.
Mr. Erdogan is likely to proceed with his purchase of the Russian S400 missile system despite American objections, said Ms. Aydintasbas, in the hopes that President Trump will soften the blow by waiving sanctions or choosing the least harsh sanctions.
“Trump is the wild card in this equation, and he may end up giving the Turkish leader the compromise he seeks,” she said.
To improve relations with Europe, Mr. Erdogan — who has fired, purged and arrested tens of thousands of people since the failed coup in 2016 — would have to release some of the political prisoners held in Turkey, Ms. Aydintasbas said.
Business leaders have also advised Mr. Erdogan that the release of detained journalists and civil society activists would smooth ties with the European Union, Bahadir Kaleagasi, the secretary general of Tusiad, an association of Turkish industry and businesses, said in a recent interview.
The mayoral election results coincided with the trial of one of the most prominent political prisoners, Osman Kavala, a philanthropist often described as the George Soros of Turkey. He has been jailed for the past 20 months, accused of trying to overthrow the government for supporting the popular protests in Istanbul’s Taksim Square in 2013.
Mr. Kavala told the judge the indictment was a “fantastical fiction” with no proof, asserting: “I have never believed in changing a government in any way other than free elections.”
One of the most strident voices in the presidential circle, the columnist Hilal Kaplan, signaled that the political fight for Turkey was by no means over.
The A.K.P. alliance may have lost Istanbul and other big cities to the opposition People’s Republican Party, or C.H.P., she reminded readers, but it won presidential and parliamentary elections last year and general municipal elections in March with 52 to 54 percent of the vote.
“Moving forward, we will watch the C.H.P. leadership trying to overcome the challenges of being in charge and governing with a multitude of partners,” she wrote.
Anger among A.K.P. members and former supporters of the party at the electoral disaster was evident on social media.
Kemal Ozturk, a former columnist for the pro-government newspaper Yeni Safak who is well-connected in government circles, said the self-interest of people close to Mr. Erdogan had boomeranged on them.
“They did such vile things as they considered everything permissible for their small interests that they stained, they damaged a huge community’s religion, cause and faith,” he posted on Twitter. “This is the real thing we should be enraged about. Losing Istanbul is small in comparison to that.”