Turkey awoke to a new political landscape on Monday after a dramatic defeat of the candidate handpicked by President Recep Tayyip Erdogan to run Istanbul, the country’s largest and most important city.

The scale and depth of Ekrem Imamoglu’s victory over former prime minister Binali Yildirim in Sunday’s vote, as well as the many still-baffling missteps by the ruling party in the mayoral elections, will likely change Turkey’s political landscape for years to come, and perhaps trigger an early vote ahead of presidential elections now scheduled for 2023.

“This is not a victory; this is a new beginning,” Mr Imamoglu said in a speech after the vote.

For the first time in his political career, Mr Erdogan did not emerge to speak in front of cameras after an election, instead tweeting his congratulations to Mr Imamoglu. Supporters of the Justice and Development Party have already begun a reckoning.

“It is being said that we have four-and-a-half years of no elections ahead of us,” Abdulkadir Selvi, a pro-government columnist, wrote in the Hurriyet newspaper. “But looking at these results, I cannot speak so confidently, because these results have a significance beyond mere elections.”

Election in Turkey: the reaction in pictures Show all 10 1 /10 Election in Turkey: the reaction in pictures Election in Turkey: the reaction in pictures Supporters of Mr Erdogan celebrate in Istanbul Getty Election in Turkey: the reaction in pictures A supporter of Mr Erdogan carries his portrait in front of a Turkish flag Reuters Election in Turkey: the reaction in pictures Following the election, a shipowner reads a newspaper that covers the result AP Election in Turkey: the reaction in pictures Supporters of Muharrem Ince, defeated opposition candidate, wait outside the Republican People's Party (CHP) headquarters following Mr Erdogan's claim of victory Getty Election in Turkey: the reaction in pictures People in an Instanbul barber shop listen to Muharrem Ince's speech following the results EPA Election in Turkey: the reaction in pictures Supporters of the pro-Kurdish People's Democratic Party (HDP) hold photos of its leader Selahatin Demirtas AFP/Getty Election in Turkey: the reaction in pictures Supporters of Mr Erdogan celebrate outside the AK party HQ in Ankara Getty Election in Turkey: the reaction in pictures Mr Erdogan waves to supporters in Ankara AP Election in Turkey: the reaction in pictures Mr Erdogan waves to supporters in Ankara AP Election in Turkey: the reaction in pictures Supporters of Mr Erdogan light flares as they celebrate the result AP

Even Mr Imamoglu’s supporters seemed in awe of the results. He had won 31 March elections later controversially annulled at the request of the ruling party by about 14,000 votes. But on Sunday, according to results which must still be certified by the higher election commission, he won the city by 800,000 out of 10 million or so votes cast.

He managed to convince voters in 12 of the 25 districts that had voted for Mr Yildirim in the last elections to switch loyalties, including conservative districts like Fatih, which has been a mainstay of the AKP or its Islamist-rooted predecessors for three decades.

“We also got votes from the AKP,” an overjoyed Yuksel Taskin, one of a new cadre of strategists for Mr Imamoglu’s People’s Republican Party (CHP), told The Independent.

“Our voters were mobilised,” he said. “The sense of being victims and being the underdog helped us. The poorest people who tended to vote AKP for years, a significant portion of them also voted for us, which is important for the future.”

The AKP’s mistakes in the election were numerous. Mr Erdogan appeared to initially accept the results of the 31 March elections before claiming irregularities and demanding a recount or rerun, granted after Mr Imamoglu had been sworn in and served as mayor for 18 days.

Many of the AKP’s own supporters were fuming; they believed Mr Imamoglu had won the election fair and square, and had been wronged.

“They failed to develop a substantial and convincing argument for the necessity to hold a re-run,” wrote Nagehan Alci in a commentary for the pro-government HaberTurk.

Some now speculate that those advisers who urged Mr Erdogan to ask for the annulment may be on their way out. “It is now time for those who misinformed our president to give account,” former AKP MP Samil Tayyar wrote on Twitter.

The AKP sought to win the second vote by appealing to its own disgruntled supporters – alienated by rising economic hardships and the increasingly opulent lifestyles of the party elite. They also sought to reach out to a rival Islamist party and Kurds who had once voted in significant numbers for the AKP as an alternative to the secular nationalists. They failed to draw all three constituencies.

But there may be deeper currents working against the AKP. Increasingly well-connected to the world via the internet and travel, Turks may be growing wary of the AKP’s tight control over broadcast television, restrictions on social media, and a ham-fisted attitude towards opposition activists and journalists.

On Friday, one of Mr Imamoglu’s political architects, Canan Kaftancıoglu, is to appear on trial on charges that she insulted the government many years ago in what many see as an attempt to damage the mayor.

Yusuf Erim, a political analyst at Turkey’s public broadcaster, cited recent reports suggesting younger Turks were growing less religious and conservative, and more tolerant of atheism and non-mainstream lifestyles in both the cities and the countryside. The AKP has failed to connect with those new voters, he said.

They need to go back to the drawing board. They need to take a step to the centre. They need to be able to cater to a broader base. The electorate is changing, and they need to evolve Yusuf Erim, political analyst

“It’s a wake up call,” he said in an interview. “They need to go back to the drawing board. They need to take a step to the centre. They need to be able to cater to a broader base. The electorate is changing, and they need to evolve.”

Others said they hoped the party returns to the winning formula it had during the early 2000s.

“It needs to focus on the national economy, and recreate the platform it had originally created for growth, individual freedoms, and democratic rights, as we did between 2002 and 2012, and which provided us with consecutive victories,” Egemen Bagis, Turkey’s former EU minister and AKP member, told The Independent.

Celebrations of Mr Imamoglu’s win continued into the early hours, with drunken, joyous revellers wandering the streets. Many inside and outside the country regarded the election as a test of Turkey’s democracy – and one that it passed.

“One thing this election is that Turkey is a true democracy, which should be respected and not be confused by some other countries,” said Mr Bagis, an Erdogan loyalist.

But Turkey still has a long way to go before it reverses its autocratic drift. Mr Erdogan’s allies continue to control parliament, and dominate the courts, and the security apparatus. Scores of journalists have been jailed and news outlets hounded out of business in recent years.

Erdogan's party challenges results of Istanbul election

On Monday, 16 activists, scholars and journalists were hustled into a courtroom to stand trial for alleged political crimes committed during the 2014 Gezi Park protests against Mr Erdogan.

And while some AKP supporters were celebrating Mr Imamoglu’s victory as a showcase of Turkish democracy, others managed to deride it as a win for outlawed organisations like the Kurdistan Workers Party or PKK, and the religious movement of exiled cleric Fethullah Gulen, both regarded by Turkey as terrorist outfits.

But the election may have also emboldened both moderate supporters of Mr Erdogan and AKP discontents who have long hinted they’d wanted to start a new party that catered to centrist voters.

For a decade-and-a-half Mr Erdogan’s biggest strength was a feckless, incoherent opposition. But Mr Imamoglu, with his upbeat, positive tone and inclusive politics – and roots in both the country’s pious Anatolian heartland and cosmopolitan commercial capital – has managed to present himself as an attractive, even inspirational, alternative.

“Tear down all prejudices in your mind,” he said in his speech late on Sunday. “We do not care about anybody’s lifestyle or beliefs. We have come to embrace everyone. We have come to embrace everyone, Alawite or Sunni. We do not have a concept of minority in this city, we will embrace the Armenians, the Assyrians, the Jews, everyone. We will build democracy in this city.”