Turkish President Recep Tayyip Erdogan's ruling party suffered a humiliating defeat on Sunday when the opposition's Ekrem Imamoglu won the re-run of the Istanbul mayoral election by a landslide.
Most analysts felt Erdogan was taking a huge risk by calling for the first vote in March to be annulled over claims of corruption.And so it proved, with Imamoglu winning by more than 800,000 votes over the ruling party's Binali Yildirim on Sunday, compared with just 13,000 votes in March.
It puts the opposition in control of Turkey's economic powerhouse, a city of 15 million which has been a vital source of patronage for Erdogan's Islamic conservative AKP for a quarter-century.
- Why did Erdogan lose? -
The AKP remains the most popular party nationwide, but recent economic difficulties, including double-digit inflation and high unemployment, have dented its standing.
Imamoglu portrayed himself as a victim whose victory had been stolen, turning the previously little-known district mayor into a household name.
That put Erdogan on the back foot for the first time, said Soner Cagaptay, director for Turkey at the Washington Institute for Near East Policy."Imamoglu was creating news and the narrative, and Erdogan was reacting to it," he said.
Kurdish voters, who number millions in Istanbul, likely played a major role, angered at the government's crackdown on Kurdish activists in recent years.
The main pro-Kurdish party, the HDP, threw its support behind Imamoglu and its flag was prominent at victory rallies on Sunday.
- What does it mean for Erdogan? -
"The AKP elites will probably try to de-emphasise the election and act like it's no big deal," said Berk Esen, assistant professor of international relations at Ankara's Bilkent University.
But Erdogan will still have to deal with internal rivals, Esen added.
There are persistent rumours that former bigwigs in the party, including ex-premier Ahmet Davutoglu and former president Abdullah Gul, who both criticised the decision to re-run the Istanbul election, are toying with the idea of founding a new party.
Sunday's defeat looks particularly damaging when taking into account Erdogan's ability to mobilise state resources and "his control of many institutions, from media to courts to election board," said Cagaptay.
However, he remains the most prominent figure in Turkish politics and has played down the importance of the mayoral vote, saying it was "only a change in the shop window" since the AKP controls almost two-thirds of the city's districts.
- What next? -
All eyes are on the AKP's alliance partner, the right-wing Nationalist Movement Party (MHP), which the government needs to maintain its majority in parliament.
A split could trigger fresh elections -- although that would be hugely unpopular in a country that has been to the polls eight times in just five years.
Erdogan still has the ability to make life difficult for Imamoglu when he takes over in Istanbul since the AKP controls the majority of seats in the municipal council.
The government has also removed mayors, particularly pro-Kurdish leaders in the southeast of the country, replacing them with centrally-appointed administrators, although this would be a risky strategy given the scale of Imamoglu's victory.