The historic city of Istanbul has fallen into Opposition hands for the first time in 25 years.

Key points: The President's request for the election to be done over backfired spectacularly

The President's request for the election to be done over backfired spectacularly The newly-elected mayor's inclusive narrative was in contrast to his rival's populist fearmongering

The newly-elected mayor's inclusive narrative was in contrast to his rival's populist fearmongering The election result could galvanise opposition parties and splinter Mr Erdogan's AKP

It was a symbolic loss for Turkish President Recep Tayyip Erdogan in more ways than one.

Mr Erdogan was elected mayor of Istanbul in 1994, launching his political career. More recently, he was widely reported to have said: "Whoever wins Istanbul, wins Turkey".

The Opposition secular candidate Ekrem Imamoglu clinched a victory in the mayoral race in March, in a race so tight that Mr Erdogan's Islamist ruling party, the Justice and Development Party (AKP), demanded a do-over, citing "irregularities".

When Turkey's election body complied and ordered a re-run, it was criticised as "plain dictatorship".

Loading

But the second tilt at the mayoral race has backfired spectacularly for Mr Erdogan's candidate, with Mr Imamoglu, from the Republican People's Party (CHP), taking his margin from 13,500 votes to more than 800,000.

With the Istanbul result, Turkey's top three cities are now held by the Opposition, marking a shift in the political landscape that has been dominated by authoritarianism and purges in a post-2016 coup crackdown.

In a country where the judiciary and election bodies sit squarely under the Government's thumb, how did Istanbul return such a result, and what does it mean for Mr Erdogan's Turkey?

Scenes of jubilation

Supporters attend a rally after Mr Imamoglu's victory in Istanbul. ( Reuters: Kemal Aslan )

On Sunday, tens of thousands of people flooded the streets of Istanbul in the wake of the result, waving flags and setting off flares in celebration.

"This re-run [election] was one to put an end to the dictatorship," Gulcan Demirkaya, a 48-year-old housewife from an AKP-leaning district, told Reuters.

"The one-man rule should come to an end."

Closer to home, Hilkat Ozgun, a scientist and the head of the Australian Turkish Cultural Platform, said political allegiances were divided in the Australian Turkish community.

But she told the ABC that for some young migrants looking for opportunities in Australia, now "they have hope that one day they can go back to Turkey".

"People are really happy about the result," Ms Ozgun said.

Mr Imamoglu had become a symbol of hope, she said.

"He'll be good for Turkey's future."

Hope wins over fear

Mr Imamoglu widely increased his margin in the election do-over. ( AP: Onur Gunay, Imamoglu media team )

What made Mr Imamoglu stand out from his opponent — former prime minister Binali Yildirim — was his tone.

"He had a very inclusive narrative, very opposite to this populist, fearmongering, and divisive or polarising narrative that the AKP Government and their allies … ran against him," Tezcan Gumus, a lecturer in Turkish politics at the University of Melbourne, said.

Mr Imamoglu, whose name means "son of an Imam", went out of his way to appeal to conservative heartlands and religious voters, at times singing the call to prayer in mosques himself, Dr Gumus said.

Mr Imamoglu waves to supporters outside a polling station in Istanbul. ( AP: Lefteris Pitarakis )

Mr Imamoglu's victory was all the more remarkable because Turkey's Opposition was routinely denied airtime and because the Government exercised control over judicial and electoral bodies, he said.

"It's absolutely staggering. It's a massive result and it shows the loss of trust they have towards Erdogan's Government," he said.

The Opposition was able to garner grassroots support, despite campaigning in an environment where upwards of 90 per cent of Turkey's television news channels and newspapers are pro-Government.

"Although there are elections, the landscape is so heavily manipulated to advantage Erdogan and his party," Dr Gumus told the ABC.

Cracks within Erdogan's party

People stand in Taksim Square in Istanbul during the attempted coup in July 2016. ( Reuters: Murad Sezer )

Almost exactly three years ago, Mr Erdogan's face was broadcast internationally, as he video-called the Turkish people from his smartphone.

A military coup was ongoing, he said, calling for his supporters to take to the streets, where gunfire and explosions rocked Istanbul and the capital Ankara.

In the resulting purge, 150,000 state officials, teachers and academics have been sacked, 500,000 people have been investigated and more than 300 journalists have been arrested.

Less than a year after the coup attempt, the country voted in a referendum to transform from a parliamentary democracy into a presidential system, cementing Mr Erdogan's grip by granting him sweeping new powers.

Winning Istanbul was not just about prestige — the city's GDP accounts for more than 30 per cent of the country's economy.

"Erdogan has fought tooth and nail not to lose Istanbul," Dr Gumus said.

"But going for a re-run — it's dented his democratic legitimacy. Because Erdogan has always throughout his career — no matter how authoritarian he is — he's always looked at the ballot box as the justification for his rule."

Turkey's President Recep Tayyip Erdogan has used the ballot box to justify his rule. ( AP: Yasin Bulbul )

He might have lost this municipal election, but Mr Erdogan still controls the levers of the Government, Dr Gumus said. The next presidential election is not slated until 2023.

"He's a political animal. He's a survivor. And four years is a long time in Turkish politics," he said.

But the Istanbul result does send a message, and could galvanise opposition parties into alliances, or also cause splintering within the AKP, where cracks are already appearing.

There are murmurs that a number of senior powerbrokers within AKP, including a former president and former prime minister, could announce the creation of rival parties that could jeopardise Mr Erdogan's rule, Dr Gumus said.

"It shows that the veneer of invincibility that the AKP has built up over them since they've been in power is actually slowly eroding," he said.