The party of Turkey’s President Recep Tayyip Erdogan has lost control of the capital, Ankara, in local elections in what is being seen as a setback to his 16 years in power.
But both his AKP and the opposition claimed to have won the mayoralty of the largest city, Istanbul.
Nationally, the president’s AKP-led alliance has won more than 51% of the vote in the municipal elections.
“If there are any shortcomings, it is our duty to correct them,” he said.
Mr Erdogan had previously said the poll was about the “survival” of the country and his party.
The election came amid an economic downturn and was widely seen as a referendum on his leadership.
More than 57 million people in the country were registered to vote for mayors and councillors.
What are the results?
Turkish media said the secularist Republican People’s Party (CHP) candidate Mansur Yavas had won a clear victory in Ankara.
However, both the CHP and Mr Erdogan’s AKP – or Justice and Development Party – claimed victory by a slender margin in the contest for mayor of Istanbul, which has been governed by AKP.
CHP candidate Ekrem Imamoglu said he had won by nearly 28,000 votes while the AKP said its candidate, former Prime Minister Binali Yildirim, was ahead by 4,000 votes.
Both candidates reportedly received more than four million votes each.
The CHP also said it had held Izmir, Turkey’s third largest city.
What has the reaction been?
“The people have voted in favour of democracy. They have chosen democracy,” CHP leader Kemal Kilicdaroglu said.
Meanwhile, Mr Erdogan, speaking to supporters in Ankara, hinted that the AKP may have lost control of Istanbul.
“Even if our people gave away the mayoralty, they gave the districts to the AK Party,” he said.
He vowed to focus his leadership on the Turkish economy ahead of national elections scheduled to take place in 2023.
Prominent journalist Rusen Cakir said the vote was “as historic as that of 1994”, referring to the year Mr Erdogan was elected mayor of Istanbul.
“It is a declaration that a page that was opened 25 years ago is being turned,” he said, according to Reuters.
Analysis by Mark Lowen, BBC Turkey Correspondent
President Erdogan had painted this election as a matter of survival. He’s now been dealt an agonising blow.
For the first time in a quarter of a century, his party has lost Turkey’s capital Ankara.
And in the economic powerhouse of Istanbul, there’s a hair’s breadth between the governing AK Party and the opposition.
As the official tally showed fewer than 3,000 votes between them in this city of 18 million, both said they’d won.
But then the count stopped, with more than 1% of ballot boxes still unopened: a tactic, says the opposition, to steal victory.
This could be a watershed moment for Turkey’s powerful, polarising president: when an opposition long seen as moribund finally feels he’s beatable.
How was the campaign?
This was the first municipal vote since Mr Erdogan assumed sweeping executive powers through last year’s presidential election.
The AKP have won every election since coming to power in 2002.
With most media either pro-government or controlled by Mr Erdogan’s supporters, critics believe opposition parties campaigned at a disadvantage.
The opposition pro-Kurdish Peoples’ Democratic Party (HDP) said the elections were unfair and refused to put forward candidates in several cities.
Some of its leaders have been jailed on terrorism charges, accusations they reject.
Mr Erdogan’s rallies have dominated TV coverage. At one on Saturday, the president sought to reassure voters and the party’s usually conservative supporters that everything was under control.
“I am the boss of the economy right now as president of this country,” he said, also blaming the West and particularly the US for its financial turbulence.
The president was criticised for repeatedly showing footage from the recent terrorism attack in New Zealand, in which a self-declared white supremacist live-streamed himself killing 50 people at two Christchurch mosques.