The turnout was a very high 84.52 percent nationwide, according to the state-owned Anadolu news agency.
The secularist Republican People's Party (CHP) overcame overwhelming media support for the AKP and an environment which European observers said fell short of requirements for "genuine democratic elections".
In Ankara, opposition mayoral candidate Mansur Yavas had 50.89 percent of votes ahead of the AKP's Mehmet Ozhaseki on 47.06 percent, Anadolu state agency reported, with 99 percent of ballot boxes counted.
Meanwhile, the race in Turkey's largest city, Istanbul, remained too close to call.
The AKP and its Islamist predecessor have controlled Istanbul and Ankara for 25 years.
Dawson urged the Turkish government to respect the election results. He did not specify which percentage of votes had been counted.
Erdogan pledged that Turkey would now focus on its troubled economy in the run-up to national elections in 2023.
Indicative pricing showed Turkey's lira falling as much at 1 percent against the dollar in early Sydney trade, before recouping losses to less than 0.1 percent as of 12:25 a.m.in Istanbul.
But in a sign of possible turmoil ahead, AKP officials said they would challenge the alleged invalidation of tens of thousands of votes in both cities.
"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 main opposition Republican People's Party (CHP) and Iyi (Good) Party formed an electoral alliance to rival the AKP and its nationalist MHP partners. Not only is the CHP the traditional party of the Turkish army, which carried out three bloody NATO-backed coups in the 20th century, but it refrained from criticizing the role of Washington and Berlin in organizing the failed 2016 coup attempt targeting Erdogan.
Central Bank "backdoor tightening" over the last week to prevent a repeat of last year's lira crisis, when the currency fell 30 percent, "did not really increase confidence in their policy making", Leuchtmann said. "Ankara has won. All of Ankara has won, hand in hand", he told supporters.
In addition to Ankara, Mediterranean tourism hub Antalya, coastal province Adana and port hub Mersin looked headed for opposition control, with candidates allied to the CHP defeating mayors who won in the last municipal elections for one of two parties in Erdogan's alliance.
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.