On 31 March, Ekrem İmamoğlu of the opposition Turkish Republican Party (CHP) was elected mayor of Istanbul at the head of a National Alliance coalition. He was sworn in on 17 April, but removed from office this week when the Supreme Electoral Council announced that the vote will be re-run on 23 June.

İmamoğlu and the CHP will not have been unprepared for the decision. In a city of more than fifteen million people, he defeated the AKP candidate, Binali Yıldırım, by 23,000 votes at first tally. The government ordered a recount. To protect against tampering, polling station officials – supporters not of İmamoğlu so much as of Turkish democracy – slept next to the sacks of ballots waiting to be recounted. İmamoğlu’s majority was reduced to less than 14,000. But he had still won.

President Erdoğan and the AKP have long used the apparatus of the state to help them win elections, from public transport to state broadcasters to prison: Selahattin Demirtaş, the leader of the pro-Kurdish People’s Democracy Party (HDP), has been detained since November 2016. In the 2017 constitutional referendum on Turkey’s new presidential system, which the government won by less than 2 per cent, there was controversy over the counting of unstamped ballots. This time they’ve gone further. It was said that Erdoğan had to choose between losing Istanbul or losing legitimacy. He has made his choice.

During his few weeks in office, İmamoğlu made a number of cosmetic but significant gestures, positioning himself as the mayor of a global metropolis. He cut public transport fares for young people. When Notre-Dame was on fire, he tweeted a message of solidarity to the mayor of Paris. He wished Istanbul’s small Christian minority a happy Easter (for secular Turks, a breath of fresh air in the Islamist fog that the AKP has summoned up as the lira has collapsed and the economy slumped).

Such moments were glimmers of the city that liberals want, but there was relief among working-class CHP supporters, too, and among middle-class Muslims dismayed at the economic recklessness of the AKP, which used to stand for a combination of fiscal prudence and piety. Beating Erdoğan with his favourite stick, people responded with both rebuke and ridicule to the fact that the rerun was announced on the first day of Ramadan.

Erdoğan seems to have gone through most of the five stages of grief since the first vote, stopping short only of acceptance. There were those in the AKP, including Berat Albayrak, the finance minister and Erdoğan’s son-in-law, who had looked forward to a long period without elections as an opportunity to focus on the country’s economic renewal.

‘If we lose Istanbul, we lose Turkey,’ Erdoğan is supposed to have once remarked. The municipality is home to nearly a fifth of the country’s population, and has an annual budget of more than 40 billion lira (nearly €6 billion). Public spending on construction projects has brought lavish private returns to AKP politicians (when Erdoğan was mayor of Istanbul in the 1990s, he was charged with 18 counts of corruption). The election result threatens a pyramid of cronyism that may be outgrowing even Erdoğan himself.

Preparations for the June election have begun in earnest. Abdullah Öcalan, the leader of the Kurdistan Workers’ Party (PKK), who has been in jail since 1999, has been allowed to meet with his lawyers for the first time in eight years. Around four million Kurds live in Istanbul; the AKP has lost their votes after years of curfews and incursions in eastern Anatolia.

The opposition’s reaction to the announcement was less calculated but more spirited. On consecutive nights, across Istanbul, people have taken to the streets. The now familiar chant of ‘AKP hırsız!’ (‘thief’) has rung out alongside the sound of pots, pans and kettles being banged, and the spring rainstorms. In the Kadıköy neighbourhood, on the night of the announcement, an old woman could be heard shouting from her window of the shame she felt at any of her neighbours who might have voted for these people. Given the concentration of the anti-government vote in the area, there won’t have been many.

If he is to win again, İmamoğlu has to hold his coalition together. Addressing his supporters, he also said he would need the backing of former AKP voters to have a chance of defeating Yıldırım a second time. Boos came from the crowd. Youthful and dynamic, he ended his speech by taking off his jacket and rolling up his shirt sleeves, urging the crowd to laugh in the face of the injuries that have been done to the electoral system. The CHP has suggested, tongue in cheek, that Erdoğan’s re-election as president last year should be annulled too. However much the Turkish government abuses the democratic process, the Turkish people appear resolute in insisting on it. The opposition is determined not only to win again in June, but to win bigger.