The results of the local elections in Turkey are a serious blow to Recep Tayyip Erdogan, who had hoped to regain control of the cities less than a year after receiving a third term as president.
He campaigned to win in Istanbul, where he grew up and became mayor.
But Ekrem Imamoglu, who first won the city in 2019, marked a second victory for the secular opposition Republican People's Party.
Erdogan promised a new era in the Turkish megalopolis of nearly 16 million people, but the incumbent mayor of Istanbul won 51 percent of the vote, more than 10 points more than the AKP presidential candidate.
It was the first time since Erdogan came to power 21 years ago that his party was defeated in a nationwide election.
In the capital Ankara, opposition mayor Mansur Yavash outpolled his rival, winning 60 percent, so he declared victory even after fewer than half the votes were counted. Supporters blocked all main roads in the city, waving flags and honking their car horns.
It is important to note that the CHP is also on track to win in many other major cities of Turkey, including Izmir and Bursa, Adana and the resort of Antalya.
President Erdogan, 70, admitted that the elections did not go as he had hoped, but told supporters in Ankara that they were "not an end for us, but rather a turning point".
He has always relied on the "will of the people" for his authority and told his supporters that he would now respect the will of the voters.
During the campaign, Erdogan said this would be his last term, which ends in 2028.
But critics believe a victory would encourage him to revise the constitution so he can run again. After such a dramatic defeat in Sunday's local elections, that seems highly unlikely.
By contrast, the result is a big success for CHP chairman Ozgur Ozel, who praised voters for deciding to change the face of Turkey in a historic vote: "They want to open the door to a new political climate in our country."
Istanbul crowds gathered outside the city hall in Saracan, one of Istanbul's oldest neighborhoods.
They waved Turkish flags and posters, on which Ekrem Imamoglu's picture was placed alongside that of Turkey's founding father Kemal Ataturk, whose poster was hung on the walls of the local government building.
"I can say that our citizens' trust and faith in us have been rewarded," Imamoglu said.
Both he and Mansur Yavash are seen as potential candidates for the presidency in 2028.
"Everything will be fine," Imamoglu supporters chanted as they danced to the sound of drums and clarinets in Saracane.
The incumbent mayor of Istanbul first used this slogan when he won the city from Erdogan's party five years ago. Some of the posters in Saracan used his current slogan: "Full speed ahead".
"This is only a local election, but the opposition's victory in the big cities is a significant show of strength against the ruling party," 25-year-old Imamoglu supporter Yesim Albayrak told the BBC.
Istanbul is home to a fifth of Turkey's population of nearly 85 million. Whoever controls the city will control a significant part of Turkey's economy, including trade, tourism and finance.
Five years ago, Imamoglu overturned the Justice and Development Party's long rule in Istanbul with the support of other opposition parties. But that opposition unity crumbled after last year's presidential election defeat, and Erdogan's party now had high hopes of overturning his victory in 2019.
Ahead of Sunday's election, the result was thought to be close, with AKP candidate Murat Kurum mounting a strong challenge.
But the ruling party has failed to shake off an economic crisis that has seen inflation hit 67% and interest rates hit 50%.
While large parts of Turkey's west, south and north are now under the control of the opposition CHP, the pro-Kurdish Dem party has gained control of much of the southeast.
Erdogan's party continues to dominate central Turkey and has had greater success in the southeastern regions devastated by the twin earthquakes of February 2023, including the cities of Kahramanmaras and Gaziantep.
Speaking from the balcony of his party headquarters in Ankara, he vowed to use the four years until the next presidential election to "renew ourselves and make up for our mistakes."
His supporters chanted in response: 'Stay calm, this nation is with you'.
Some 61 million Turks were eligible to vote in Sunday's election, and more than a million young voters cast their ballots for the first time. Turnout in the country's 81 provinces was estimated at more than 77%./BGNES