Editor’s Note: This article originally appeared on Order from Chaos.

Following a repeat mayoral election in Istanbul on June 23, Turkish strongman Recep Tayyip Erdoğan is not quite so strong anymore. If there is one thing worse than losing a close election, it must be losing the same election twice—and the second time with a much wider margin.

This is what the Turkish president’s Justice and Development Party (AKP) experienced as polls confirmed that the opposition candidate and the new darling of Turkish democrats, Ekrem İmamoğlu, won in a landslide. Ruling party candidate Binali Yıldırım, a former prime minister and close ally of Erdoğan, conceded the race shortly after the results showed his opponent gathered 54% of the votes, compared to 45% for AKP. When the initial vote was held on March 31, İmamoğlu won by fewer than 14,000 votes; last weekend, he increased his votes more than 50-fold to win by just over 800,000 votes.

Erdoğan’s tactical gamble of forcing a re-run election in Istanbul—something only an autocrat could do—is now proving to be a strategic mistake, with dire consequences for perpetuating his and the AKP’s 17-year national-level rule. By losing Istanbul with a wide margin, Erdoğan not only exacerbated his defeat in the most consequential of cities in Turkey, but he also confirmed an already widely held perception that he is losing control of hearts and minds in the country. This is likely to open prospects for democratic restoration in Turkey.

How a Re-run Helped the Opposition

Having lost the original election, the AKP had appealed to overturn the March results, claiming the election was stolen. In reality, Erdoğan got the vote nullified because the result was unacceptably close. After all, only two years earlier, it was Erdoğan himself who had admitted: “If we lose Istanbul, we lose Turkey.”

The Supreme Electoral Council (with a majority of pro-AKP judges) ruled in favor of repeating the election, based on a trumped-up technicality that there were irregularities in the staffing of observers at the polling stations. Their decision was the latest of a series of strikingly autocratic moves by the AKP government. Yet, nothing seemed to surprise anyone in a country where the media is muzzled, the most popular opposition leader is in jail, 1,400 civil society organizations has been closed, and 140,000 civil servants have been dismissed. This is the new Turkey Erdoğan created by transforming the seven decades-old parliamentary system into an imperial presidency marked by the stark absence of checks and balances. Both in the 2017 referendum that changed the governing system and the June 2018 presidential election when he officially placed himself atop that system, elections were considered far from being “free and fair.”

By canceling Istanbul’s original result, Erdoğan should have known that he was playing with fire. In the absence of the rule of law, freedom of speech, freedom of assembly, and a free media, the ballot box remained the only institution that enjoyed a certain level of legitimacy in terms of representing the will of the people. The cancellation also betrayed his repeated line that winning elections represented the national will, a notion he employed to legitimize his increasingly populist, autocratic, and nationalist presidency.

If the decision to repeat the Istanbul municipal election was a tactical blunder, the presidential system Erdoğan established proved to be a major strategic miscalculation. By switching from the old parliamentary system—which permitted the AKP to enjoy legislative majorities with less than 40% of the popular vote—into a presidential one, Erdoğan not only condemned himself to the requirement of a 50%-plus majority in national elections but also inadvertently achieved something that all autocrats normally try to avoid: the unification of the opposition.

Before the presidential system, the Turkish opposition was notoriously divided. One unexpected consequence of the new system was the dynamics it generated for opposition parties to come together and form coalitions among themselves. Ironically, this dynamic was accelerated when Erdoğan, recognizing his falling popularity and the mathematics that his new system generated, rushed legislation through the parliament to enable AKP to form an electoral alliance with the right-wing Nationalist Action Party (MHP) ahead of the 2018 presidential election. In return, the Republican People’s Party (CHP) followed suit, allying itself with the Good Party, a splinter party from MHP. For the mayoral election, İmamoğlu also received the informal support of the Peoples’ Democratic Party (HDP), a political party representing an important portion of the Kurdish vote nationally and in Istanbul too.

Nullifying the Istanbul election was unwise, not only because it helped to close ranks among the opposition coalition, but also because it turned İmamoğlu into a victim and then a hero. The Turkish electorate has long had a reputation for siding with victims, a quality that used to benefit Erdoğan. These two dynamics, on top of voter defections from AKP ranks uncomfortable with the cancellation, enabled an almost 10-point win for İmamoğlu.

Since the restoration of democracy in 1983, after the military coup of 1980, never in Istanbul’s history had a candidate managed to win with such a majority. Erdoğan’s legendary rise in national politics was preceded by a modest 25% win for the Istanbul mayorship in 1994—actually, thanks to a very divided opposition. Turkish voters love victimhood and İmamoğlu, the son of a center-right political family from the Black Sea region and former mayor of a small sub-district of Istanbul, played that role with dignity when his victory was stolen. Instead of turning his victimhood into an aggressive attack against Erdoğan, İmamoğlu once again ran a campaign based on bread-and- butter issues with a message of love, empathy, and national reconciliation. In a society tired of Erdoğan’s angry polarization tactics, such a discourse proved highly refreshing and much welcomed.

More Blunders from the AKP

The AKP, for its part, seemed confused and destabilized. Wavering between contradictory responses, Binali Yıldırım first tried to emulate his adversary by promising generous subsidies and perks to Istanbul residents. Cheaper access to transportation, water, internet, schools, and a massive job-creation program were promised. Some of these pledges looked suspiciously close to İmamoğlu’s planned projects. In a rare televised debate with İmamoğlu, he was unable to offer a satisfactory answer to why there was a re-run election and who had actually stolen the AKP’s alleged victory. Erdoğan remained absent from the political scene, probably in an effort to depolarize the election and make it about Istanbul’s problems rather than his own legacy. But in the last stages of the campaign, he couldn’t help himself, and re-emerged with a vengeance in full-attack mode.

His smear campaign ranged from accusing İmamoğlu of being a crypto-Greek to having sympathies for the U.S.-based Islamic preacher Fethullah Gülen, to stealing the original vote and having ties with Kurdish terrorists. Then came the ultimate contradiction, when the AKP tried to convince Istanbul’s large Kurdish community to stay home by asking the militant Kurdistan Workers Party (PKK) leader Abdullah Öcalan, who is serving a life sentence in jail for terrorism, to write a letter telling them to do so. Worse, he could not resist using the death of Mohammed Morsi to arguein an election rally that a vote for the opposition would be a vote for the likes of Abdel Fattah el-Sissi in Turkey. It was an approach very reminiscent of the callous and instrumentalist way in which he had exploited the attacks on mosques in New Zealand just ahead of the March 31 elections in a frantic effort to mobilize votes. All these desperate and contradictory moves proved too little too late, especially for AKP voters increasingly listening to their conscience and to İmamoğlu’s narrative, rather than to their traditional party allegiances.

What Next?

At the end of the day, a deteriorating economy, a unified opposition, and a very effective candidate proved insurmountable for the AKP. The bottom line of Turkish democracy—“those who come with the ballot box leave with the ballot box”—prevailed. İmamoğlu’s landslide victory in Istanbul is inevitably going to unleash forces of transformation inside Erdoğan’s ruling AKP, but also national forces demanding democratic restoration.

Only time will tell what these forces will mean for the future of Erdoğan and his presidential system. As the former mayor of Istanbul, he surely knows all too well that who controls Istanbul is exceptionally well-placed to eventually control the whole country.