ANKARA, TURKIYE -- Turkiye's main opposition party retained its control over key cities and made huge gains elsewhere in Sunday's local elections, preliminary results showed, in a major upset to President Recep Tayyip Erdogan, who had set his sights on retaking control of those urban areas.

With nearly 60 per cent of the votes counted, incumbent mayor Ekrem Imamoglu, of the Republican People's Party, or CHP, was leading in Istanbul, Turkiye's largest city and economic hub, according to state broadcaster TRT. Mansur Yavas, the mayor of the capital Ankara, retained his seat with a large margin, the results indicated.

The CHP appeared to be leading in 36 of Turkiye's 81 provinces, according to the results reported by TRT.

The vote was seen as barometer of President Erdogan's popularity as he sought to win back control of key urban areas he lost to the opposition in elections five years ago. The CHP's victory in Ankara and Istanbul in 2019, had shattered Erdogan's aura of invincibility.

The main battleground for the 70-year-old Turkish president was Istanbul, a city of 16 million people where he was born and raised and where he began his political career as mayor in 1994.

The result came as a boost for the opposition, which was left divided and demoralized after a defeat to Erdogan and his ruling Islamic-oriented Justice and Development Party, or AKP, in last year’s presidential and parliamentary elections.

“The voters decided to establish a new political order in Turkiye,” CHP leader Ozgur Ozel told a crowd of jubilant supporters. “Today, the voters decided to change the 22-year-old picture in Turkiye and open the door to a new political climate in our country.”

A large crowd, meanwhile, gathered outside Ankara City Hall to celebrate Yavas’ victory. “Ankara is proud of you!” supporters chanted.

Sinan Ulgen, director of the Istanbul-based Edam think tank, said “the surprising outcome" was due to voters wanting to punish the ruling party over the “depth of an economic malaise.” Skyrocketing inflation has left many Turkish households struggling to afford basic goods.

AKP supporters opted to stay away from the ballot stations or voted for other parties, Ulgen said.

“Turnout was relatively low compared to past elections,” he said. “There were cross-party shifts in the vote, which did not happen in the nationals elections because of stronger ideological attachments. This time around the economy prevailed over identity.”

Some 61 million people, including more than a million first-time voters, were eligible to cast ballots for all metropolitan municipalities, town and district mayorships as well as neighborhood administrations.

Turnout was around 76 per cent, according to the state-run Anadolu Agency, compared to 87 per cent last year.

Some 594,000 security personnel were on duty across the country to ensure the vote goes smoothly. Nevertheless, one person was killed and eleven others were hurt in the city of Diyarbakir where a dispute over the election of a neighborhood administrator turned violent, the state-run Anadolu Agency reported. At least six people were also injured in fighting that erupted in the nearby province of Sanliurfa.

"According to the data we have obtained, it seems our citizens' trust in us, their faith in us has paid off," Imamoglu said of the early results.

Imamoglu won some 50 per cent of the votes in Istanbul while AKP’s candidate Murat Kurum, a former urbanization and environment minister, received 41 per cent, according to TRT. Polls had pointed to a close race between the two.

Polls had pointed to a close race between Istanbul's incumbent mayor, Imamoglu, and the AKP's candidate Murat Kurum, a former urbanization and environment minister.

Imamoglu -- a popular figure touted as a possible future challenger to Erdogan -- ran without the support of some of the parties that helped him to victory in 2019. Both the pro-Kurdish Peoples’ Equality and Democracy Party and the nationalist IYI Party fielded their own candidates in the race.

Both the pro-Kurdish Peoples' Equality and Democracy Party and the nationalist IYI Party fielded their own candidates in the race.

A six-party opposition alliance led by CHP disintegrated after it failed to oust Erdogan in last year's election, unable to capitalize on the economic crisis and the government's initially poor response to last year's devastating earthquake that killed more than 53,000 people.

Hamish Kinnear, a senior Middle East and North Africa analyst at risk intelligence company Verisk Maplecroft, said that if Imamoglu hangs on in Istanbul, "he will be well placed to unify the fractious opposition and launch a bid for the presidency in 2028."

However, losing Istanbul would deal a significant blow to both Imamoglu and the opposition, Kinnear said.

Meanwhile, a new religious-conservative party, the New Welfare Party, or YRP, is appealing to voters who have been disillusioned with Erdogan's handling of the economy and was expected to draw some votes away from his candidates.

In Turkiye's mainly Kurdish-populated southeast, the DEM Party was poised to win many of the municipalities but it's unclear whether it would be allowed to retain them. In previous years, Erdogan's government removed elected pro-Kurdish mayors from office for alleged links to Kurdish militants and replaced them with state-appointed trustees.

Erdogan, who has presided over Turkiye for more than two decades -- as prime minister since 2003 and president since 2014 -- has been advocating a new constitution that would put family values at the forefront. He does not have sufficient votes to enact a new constitution now, but a strong showing could allow him to woo some conservative, nationalist or Islamic legislators from the opposition camp for a needed two-thirds majority.

Berk Esen, an associate professor of political sciences at Istanbul's Sabanci University, said Erdogan is pushing for a new constitution "more conservative than the current version" to expand and define his legacy.

This is where the local elections come in.

"This would be a big opportunity for Erdogan to leave his political imprint," Esen said.