With 99.8 percent of ballot boxes opened in Ankara, CHP mayoral candidate Mansur Yavas had secured 50.9 percent, giving him a 3.8-percentage-point lead over his AKP rival.
The pro-Kurdish opposition Peoples Democratic Party (HDP), which Erdogan has accused of links to Kurdish militants, has not made an official alliance and is not fielding candidates for mayor in Istanbul or Ankara, which is likely to benefit the CHP.
However, the opposition is leading in the capital, Ankara, with 49.5 percent of the votes, according to TRT, in a setback for Erdogan whose ruling party and its predecessor have held the mayoral seat for 25 years.
One person was stabbed as 15 people clashed in a row between candidates in Istanbul's Kadikoy district, a police source said. Despite the fact that the final results of the vote in Istanbul have not been announced yet, Yildirim has already declared his victory.
Recep Tayyip Erdogan and his wife Emine greet supporters in Ankara.
Erdogan has campaigned heavily for his party's candidates, declaring Turkey's economic woes "an attack" on the country and framing the elections on Sunday as matter of "national survival".
Kurdistan 24 teams in Istanbul, the Turkish capital of Ankara, and Kurdish cities of Diyarbakir and Van have been following the elections.
Turkey's ruling Justice and Development (AK) Party's mayoral candidate for Istanbul, Binali Yildirim, won the majority of ballots from the box in which he cast his vote, according to unofficial results on Sunday.
"My expectation is there will be good things coming out of this election, we will win with a big difference", said Sinan, an AKP supporter speaking after voting in Istanbul.
Gonul Ay, 38, said she voted for the ruling party and Yildirim in Istanbul because of his experience.
Solskjaer told to persist with Sanchez by Manchester United board
He has performed the cultural reset, but as he admitted in his news conference Thursday, this is when the hard work really begins. Watford have been cast as the fall guys in Solskjærfest 2019, but there's no real reason to expect them to submit here.
The vote will be the first time since 2002 that the AKP is fielding candidates with its alliance partner, the rightwing Nationalist Movement Party (MHP).
President Erdogan has been Turkey's most popular and most divisive leader in modern history.
Analysts say the elections are a referendum on Erdogan's policies since parliamentary and presidential polls in June, when he promised a 'new Turkey.
The BBC's Mark Lowen says the AKP is in danger of losing key cities where opposition parties have come together in a rare act of unity in a polarised country.
Critics say that with most media either pro-government or controlled by Erdogan supporters, opposition parties campaigned at a disadvantage because Erdogan's daily rallies dominated TV coverage.
Turkish President Recep Tayyip Erdogan prides himself as a builder and manager of cities.
With inflation at just under 20 percent and unemployment at a near 10-year high in December, Erdogan has sought to reassure voters about the economy. Some of its leaders have been jailed on terror charges, accusations they reject. He blamed the lira currency fall on a campaign to undermine Turkey, led by the United States.
A consummate campaigner, he has been the country's most popular - although divisive - modern politician, tightening his hold on power in elections past year that ushered in an executive presidency, approved in a bitterly fought 2017 referendum.
With reference to Erdogan, Kilicdaroglu said: "If there is a survival issue in Turkey, it's because of you".