(Bloomberg) -- A series of miscalculations and a refusal to recognize the depth of discontent with a weakening economy and years of divisive rule handed Turkey’s President Recep Tayyip Erdogan the biggest setback of his career.

Four major factors helped Ekrem Imamoglu, a little-known Istanbul district mayor, trounce the candidate from Erdogan’s ruling AK Party on Sunday night and cruise to victory in the repeat election the president demanded.

  • Stubbornly high joblessness and the prospect of a double-dip recession weighed heavily on voters’ minds
  • Many voters, including AKP loyalists, thought the original vote was stolen because Erdogan wouldn’t accept defeat at the ballot box
  • The president alienated nationalists by mobilizing a jailed Kurdish militant leader to help with the campaign
  • Imamoglu’s message of unity resonated with a wide range of voters after years of polarizing rhetoric from Erdogan and his penchant for painting all opponents as a threat to the state

“Those who voted for stability in the past voted this time against a life in which everything is decided from Ankara,” said Bekir Agirdir, head of the Konda polling agency that successfully predicted Imamoglu’s margin of victory.

Source of Strength

For years, Erdogan’s ability to build a strong economy was the source of his electoral strength, but questionable policies including growth at all costs have sent inflation raging and the lira crashing.

The currency climbed as much as 1.8% against the dollar on Monday -- the most in the world -- as investors cheered an end to months of uncertainty over the municipal vote. But gains pared due to the threat of U.S. sanctions over Ankara’s planned receipt of the Russian S-400 missile-defense system.

Delivery is expected as early as the first week of July, and Erdogan is hoping to leverage his personal rapport with President Donald Trump to avoid penalties that, at their harshest, could cripple Turkey’s economy.

Erdogan has repeatedly rejected suggestions that Turkey could ask the International Monetary Fund for a bailout or cancel the S-400 deal,” said Wolfango Piccoli, co-president of Teneo Intelligence in London. “Reversing either of those positions now would seriously damage his standing with his support base.”

Erdogan Faces Rare Rebellion Within His Party as Economy Weakens

There’s been speculation that the party might splinter, with some members dissatisfied with Erdogan’s policies breaking away to form offshoots. The president also alienated some nationalist voters by co-opting a jailed Kurdish separatist militant leader they revile into the election campaign. That’s undermined the continued survival of AKP’s alliance with the nationalist MHP party, which the ruling party needs to maintain its parliamentary majority.

Mustafa Yeneroglu, an AKP lawmaker critical of the revote, said the party must take stock of its own failures. “We lost Istanbul because we lost our moral high ground,” he said on Twitter.

Erdogan Shifts Focus From Istanbul Loss to Foreign Affairs

Imamoglu took Istanbul with an upbeat message of unity that contrasted sharply with Erdogan’s polarizing rhetoric. “Everything is going to be great,” was his campaign slogan, and his approach resonated across party lines.

Hundreds of thousands of people thronged Istanbul’s streets after the election results came in, honking car horns and waving national flags, seeing the emergence of a potential rival to Erdogan in the presidential election of 2023, the year of Turkey’s centenary. The mayor’s job in Istanbul, the seat of the Byzantine and Ottoman empires, launched Erdogan’s own political career.

Imamoglu’s victory will further fuel the already growing sense among Erdogan’s opponents and many members of his own party “that his career is now in irreversible decline,” Piccoli said. Yet faced with a revitalized opposition and splinters within his own party, “Erdogan’s instinct is likely to be to try to tighten his grip on power rather than relax it,” he added.

On Sunday night, Erdogan vowed to “work toward our 2023 goals without making concessions on democracy, the rule of law, the peace and stability of our country.” Yet even before the balloting began, Erdogan hinted the new mayor could run into legal problems. He’s suggested there could be room to prosecute Imamoglu for allegedly insulting a provincial governor -- much as he himself was ousted from the Istanbul mayor’s office in a political case in 1998.

To contact the reporters on this story: Selcan Hacaoglu in Ankara at shacaoglu@bloomberg.net;Firat Kozok in Ankara at fkozok@bloomberg.net

To contact the editors responsible for this story: Onur Ant at oant@bloomberg.net, Amy Teibel, Paul Abelsky

©2019 Bloomberg L.P.