When Yildirim spoke, the state-run news agency showed 98.8 percent of votes tallied, and then stopped reporting updated results for Istanbul after he declared victory.
However, "the process has been continuing" as there were over 300,000 invalid votes, Binali Yildirim, the Justice and Development Party (AKP) candidate, said in a televised speech.
Yildirim accepted that his rival was leading but said his party would file an objection, suggesting a recount of the 319,500 votes declared void in Istanbul.
AK Party candidates got the support of 44.42 percent of voters on Sunday, beating the 30.07 percent draw of the main opposition Republican People's Party's (CHP), which won mayoral races in 11 metropolitan municipalities and 10 cities.
In Istanbul, a city where Erdogan had sometimes described victory as like winning Turkey itself, the race had been very tight.
In Ankara, Turkish broadcasters said the CHP candidate had won a clear victory, but the AKP said it would appeal in districts across the city and expected to shift the outcome in its favor. Many former partners might think twice before resuming an alliance after Erdogan's campaign condemnation of opponents he said were linked to terrorists. Erdogan's Justice and Development Party has been in control of the city for over 15 years.
Dawson urged the Turkish government to respect the election results.
U.S., China see progress in Beijing trade talks
The US delegation arrived in Beijing on Thursday and began discussions with Chinese officials over a working dinner. Mnuchin said in a tweet Friday that he looked forward to continuing the talks in Washington next week.
Opposition hopes that dissatisfaction at inflation and rising unemployment would be enough to dissuade working-class AKP voters from turning up to vote appeared to be well-founded.
As the economy slipped into recession and the lira lurched from one crisis to another, the president has lashed out at enemies at home and overseas, warning bankers of a "heavy price" to pay after the elections for feeding the currency chaos.
The HDP is alleging electoral fraud in one such city, Sirnak, which it carried in the last election with 59.6 percent of the vote, but lost this time to the AKP, which won 61.9 percent of the vote.
He argued, however, that a pause in elections until 2023 would benefit Erdogan.
"I am afraid we.are not fully convinced that Turkey now has the free and fair electoral environment which is necessary for genuinely democratic elections in line with European values and principles", said Andrew Dawson. The opposing camp led by the Republican People's Party, or CHP, had 37.6 percent, Anadolu reported.
Erdogan has waned at rallies that if the opposition candidate wins in Ankara, residents would "pay a price" and accused his rivals of terrorist supporters aiming to ruin Turkey.
At home, the head of Turkey's opposition Nationalist Movement Party (MHP), Devlet Bahceli, as well as former Prime Ministers Tansu Ciller and Mesut Yilmaz also sent congratulations to Erdogan.
They failed to capitalize on mounting discontent with the economic crisis in Turkey, which has seen inflation skyrocket and unemployment rise to 13.5 percent (nearly 25 percent among youth), and on deep-rooted opposition in Turkey to North Atlantic Treaty Organisation and imperialist wars.