It will need to if it wants to keep up its electoral momentum.

Last-ditch efforts to woo the Kurds failed. The Kurds tipped the outcome in Imamoglu’s favor in even greater numbers than they had in March. That their role proved so central is one of the most hopeful developments of the past months. Should the CHP sustain its newly liberal stance, it may nurture a sense of greater participation and belonging amid Turkey’s estimated 16 million Kurds, who live in far greater numbers in Istanbul than any other city in the world.

Western diplomats cynically intoned that Erdogan would do so, cheating his way to victory if need be. But few counted on the apocalypse that was in store. Cheating was apparently not an option: AKP strongholds like Fatih and Uskudar, where Erdogan maintains his private residence, fell to the opposition, a resounding signal that his oversize sense of entitlement coupled with a poorly managed and polarizing campaign had backfired spectacularly. Rising inflation and joblessness are however among the AKP’s biggest woes.

Ekrem Imamoglu, the once obscure former Republican People’s Party (CHP) mayor of Beylikduzu, an ugly urban sprawl on the edge of Istanbul, defeated his governing Justice and Development Party (AKP) rival Binali Yildirim by a whopping 800,000 votes compared with the measly 13,000 ballots in the first run. The result is widely seen as the biggest setback faced by the country’s President Recep Tayyip Erdogan, who pressured electoral authorities to invalidate the March 31 results in Istanbul in the hope of winning this time.

The opposition’s stunning landslide victory in yesterday’s controversial redo of the Istanbul municipal polls has reignited hopes that Turkey’s democracy, which seemed to be in its death throes, has some fight in it still.

The secular elite that long dismissed the Kurds, the country’s fastest growing demographic, as “mountain Turks” and oversaw their brutal repression by Turkey’s once omnipotent generals had to rely on their generosity to wrest Istanbul from the AKP and its Islamist forerunners who governed the megapolis for the past 25 years.

Equally heartening, Turkey’s urban secular class has decisively shaken off its reliance on the army to maintain order — and a facade of democracy — embracing coalition-building with pious conservatives to alter its fate.

In a perfect world, Imamoglu, with his pledges of inclusiveness, justice and transparency, could erect a model of governance for the entire country — one where a tight circle of cronies no longer laps at the trough, where ever shrinking green space is not forfeited for narrow commercial gain and gender equality becomes the norm. Just as critically, Kurds, Armenians, Alevis and Jews among a host of other minorities would finally be granted all the rights bestowed on the Sunni Turkish majority.

But will the affable 49-year-old mayor elect be allowed to do so? What will a bloodied Erdogan’s next move be? Amid all the euphoria, the hard truth is that this hopeful moment could presage a darker hell, depending on which path Turkey’s longest serving leader takes.

Ideally, the trouncing in Istanbul will shake him into more rational behavior. Erdogan will dump his informal coalition partner, the far-right nationalist Devlet Bahceli, together with his son-in-law, Economy Minister Berat Albayrak, and hawkish (and proudly homophobic) Interior Minister Suleyman Soylu. He will seek relief from the IMF, disentangle Turkey from Russia and mend fences with the United States. Tens of thousands of political prisoners will be freed starting with philanthropist Osman Kavala, who appeared in his first courtroom hearing on bogus terrorism charges today, and politician Selahattin Demirtas, the most consequential Kurd to emerge in Turkey since the imprisoned Kurdish militant boss Abdullah Ocalan.

Erdogan and his party do not face reelection until 2023. Hence, in theory, he could take urgently needed measures to put the country back on track. And his initial reaction to the Istanbul result, congratulating Imamoglu in a tweet, could be seen as heralding a return to reason.

But it may be too late. Since elbowing his way into his coveted executive presidency in 2017, Erdogan appears to have lost the political instincts that helped him survive and thrive in the face of unremitting challenges to his rule. Bahceli’s men and instinctively anti-American others are said to have filled the vacuum in the judiciary and security services left by the massive purge of suspected followers of his archnemesis Fethullah Gulen. A divorce would be messy, to say the least. A pundit told Al-Monitor on condition that he not be identified by name, “Erdogan and the AKP are political corpses that cannot be brought back to life.”

Scenting the end, a paranoid Erdogan may double down, burning Turkey’s bridges with the West and driving the economy further into the ground. He could, among other things, cut off government funding for Imamoglu and fellow opposition candidates who won the other major cities of Ankara, Mersin and Antalya. Worse, he might even lock some of them up. Ominously, Erdogan recently alluded to his own stint in jail after being elected Istanbul’s first Islamist mayor in 1993 for reciting verses from a nationalist poem deemed to incite religious insurrection, saying Imamoglu might suffer a similar fate.

Some say this overwrought scenario could be averted if Erdogan’s former allies ride to the rescue, paradoxically, by targeting the AKP. There have been long running rumors that in addition to former Prime Minister Ahmet Davutoglu, who is launching a new party, former President Abdullah Gul and former Economy Minister Ali Babacan are in the midst of forming their own party that could become a magnet for a swelling body of disgruntled AKP members, including pious Kurds. They could strike a deal with Erdogan, offering him a safe and dignified exit when his term expires, the hopeful reasoning goes.

Timing is of essence. Should the famously risk-averse Babacan and Gul fail to strike when the iron is hot, they could well become the next victims of Erdogan’s crusade against his adversaries. Turkey, in the words of the pundit, would then go, figuratively speaking, from “being a partial open air prison to a fully fledged one for all.” The safest prediction is that Turkey will remain unpredictable for the foreseeable future.