The opposition is also ahead in the contest for mayor of the largest city, Istanbul, the election commission says.
Nationally, the president’s AKP-led alliance has won more than 51% of the vote in the municipal elections.
The vote, see as a verdict on Mr Erdogan’s rule, has been taking place during an economic downturn.
The currency, the lira, has been losing value recently and the economy went into recession in the last three months of 2018.
The president had previously said the poll was about the “survival” of the country and his party.
Commenting on the results in a speech on Sunday, he said: “If there are any shortcomings, it is our duty to correct them.”
More than 57 million people in the country were registered to vote for mayors and councillors. State-run Anadolu news agency said turnout was high at just under 85%
Istanbul has been in the hands of parties linked to Mr Erdogan since 1994 when he was elected the city’s mayor.
The election commission said the CHP’s Ekrem Imamoglu was leading there by only 28,000 votes, but added that the results of more than 80 ballot boxes were being challenged.
Both CHP and Mr Erdogan’s AKP – or Justice and Development Party – had been claiming victory in the city.
The AKP had been saying its candidate, former Prime Minister Binali Yildirim, was ahead by 4,000 votes. Ruling party officials said they would challenge thousands of ballots in Istanbul and Ankara.
The CHP also said it had held Izmir, Turkey’s third largest city.
“The people have voted in favour of democracy. They have chosen democracy,” CHP leader Kemal Kilicdaroglu said. 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.