Supporters of Ekrem Imamoglu celebrate in Istanbul on Sunday. (Lefteris Pitarakis/AP)

Soner Cagaptay is a senior fellow at the Washington Institute for Near East Policy and author of “The New Sultan: Erdogan and the Crisis of Modern Turkey.”

There was a time when Turkish president Recep Tayyip Erdogan ran laser-beam-sharp election campaigns, winning poll after poll. Not anymore. On Sunday, Erdogan’s hand-picked candidate in Istanbul’s mayoral race, Binali Yildirim, lost to Ekrem Imamoglu in a clear-cut defeat.

The vote in Istanbul was a repeat of the March 31 election, in which Imamoglu defeated Yildirim by a thin 0.2 percent margin. After Erdogan’s Justice and Development Party, or AKP, lodged a complaint, the election board in May decided to have the Istanbul vote annulled because of alleged irregularities and called for repeat elections on June 23. But in a shock to Erdogan, Imamoglu not only defeated Yildirim, but did so by nearly 10 percentage points.

This is bad news for Erdogan, especially because he is, in some ways, responsible. The root of this problem lies in his transformation of Turkey’s political system — by a narrowly-approved referendum in 2017 — from a parliamentary democracy to a presidential system.

The new system, which was launched in July 2018 and has put all branches of government under Erdogan’s control, has had dramatic repercussions in less than a year. It has weakened Turkey’s institutions — from the foreign ministry to the judiciary — while resulting in the hyper-centralization of the country’s decision-making process to Erdogan’s base in Ankara.

Before, Erdogan could draw on a large cadre of advisers, ministers and government agencies to make sound decisions that helped him win elections and steer Turkey through its troubles. Now, however, the president is surrounded by a small group of aides who provide an ill substitute for Turkey’s historically competent institutions and their subject-matter experts. Erdogan’s erstwhile network of political confidants, which helped him win nearly a dozen elections, has also been sidelined to the benefit of a small inner circle.

In 1980, Dennis Ross published a trailblazing article entitled “Coalition Maintenance in the Soviet Union” on decision-making among elites. He argued that in the narrow confines of the Kremlin, the decision-making process had become distorted. Often, decisions were made, not based on what was best for the country or party, but what would best serve the narrow interests of one clique versus another.

This distortion is exactly the problem that Erdogan and Turkey have been facing since the country switched political systems last summer.

Take, for instance, Erdogan’s reaction to Yildirim losing the March 31 election. At the time, the rational decision for Erdogan would have been to accept Imamoglu’s victory. Erdogan’s party already controls Istanbul’s city council, and it would have been an easy task for him to undermine Imamoglu through the machinations of city-hall politics. However, reportedly guided by a clique of advisers, Erdogan instead pushed the election board for another vote, paving the way for Sunday’s humiliation. Even worse for Erdogan, his decision to veto the March 31 result seems to have only boosted Imamoglu’s popularity, creating a sort of "new Erdogan” — a politician who represents people marginalized by the system.

The campaign for Yildirim also oscillated wildly on various political positions, confusing and alienating the electorate. For instance, earlier in the campaign season, some advisers in the palace attempted to discredit Imamoglu by alleging that the Kurdistan Workers’ Party (PKK), a terror-designated entity, supported him. Then, just days before the vote, they pointed to a letter from the PKK’s jailed leader, Abdullah Ocalan, asking for a party to not take sides — a statement that was widely interpreted as a tacit backing of Yildirim.

This lack of a broader strategy is also a problem in foreign policy. For instance, Erdogan’s advisers have taken the lead on the crucial S-400 debate over whether to push forward with buying a Russian-made missile defense system, undermining the experienced diplomats and foreign policy experts who should handle such a sensitive issue.

If Ankara goes ahead with this purchase, this step will trigger U.S. sanctions against Turkey, which could rupture historic Turkish-American ties. However, some of Erdogan advisers are playing down the ramifications of the S-400 purchase and are pushing for the risky deal with Russia to be made.

Turkey is too large demographically, too big economically and too complicated politically to be governed from a palace. For Erdogan to thrive again in the polls, and for Turkey to effectively tackle national problems, Erdogan needs to revitalize interaction inside the executive branch, decentralize policy-making away from Ankara and look outside of his palace for solutions.

If you’re thinking that the way forward sounds an awful lot like the parliamentary system that existed in Turkey before Erdogan’s referendum, you would be right.

Read more:

Henry Olsen: Turkey’s elections in Istanbul shows that democracy is tough to subvert

Asli Aydintasbas: Erdogan faces a choice — and Turkey’s democracy is at stake

Ekrem Imamoglu: How I won the race for mayor of Istanbul — and how I’ll win again

The Post’s View: Istanbul might again reject Erdogan’s authoritarianism

Can Dundar: Why Istanbul could decide the fate of Turkey’s election