Even before the final figures were announced, Erdogan's ally and former prime minister Binali Yildirim said he won the race in Istanbul, Turkey's commercial hub, a claim rejected by the opposition, which said it won.
In Istanbul, Turkey's largest city, the race for mayor was deadlocked with the AKP candidate claiming victory with 48.70 percent of votes, but his opponent on 48.65 percent also saying he had won, after nearly all ballot boxes were counted there.
Think your friends would be interested?
Erdogan's AK Party-led alliance had 51.7 percent of the national vote, with 91 percent of the ballot boxes opened, the state-run Anadolu Agency reported.
The source added that Istanbul - Turkey's largest city - accounted for 40 percent of Turkey's economy, meaning that any slowdown would hit the city hard.
Yesterday, voters went to the polls in municipal elections held across Turkey.
"The people have voted in favor of democracy, they have chosen democracy", opposition leader Kemal Kilicdaroglu said, declaring that his secularist CHP had taken Ankara and Istanbul from the AK Party (AKP) and held its Aegean coastal stronghold of Izmir, Turkey's third largest city.
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.
Sunday's local elections were widely seen as a gauge of support for Erdogan as the nation of 81 million faces a daunting economic recession.More news: 'Us' Had the Biggest Opening Ever for An Original Horror Movie
More news: Huawei P30 Pro’s 5x optical zoom steps up phone camera wars
More news: Mike Trout's Expected $432 Million MLB Deal Will Make History
In a speech early on Monday, Erdogan pledged to focus on Turkey's economic troubles.
Rating agency Moody's said on April 1 that the central bank's use of reserves to prop up the lira currency posed renewed questions about its transparency and independence.
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.
Much of the AKP's success has been down to Erdogan's perceived economic prowess, but days before the vote, the Turkish lira was sliding again, provoking memories of the 2018 currency crisis that badly hurt Turkish households. On Saturday, Erdogan threatened: "We will definitely solve the Syria issue on the field, if possible, and not at the negotiating table, as out first task after elections".
"Most probably he will emphasize guaranteeing a certain level of economic growth until the next general elections", said Emre Erdogan, a professor at Istanbul Bilgi University and no relation to the president.
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.
In Ankara, Yavas - the candidate for both the opposition Republican People's Party or CHP and the nationalist Good Party - claimed victory in a large rally full of supporters waving red Turkish flags and setting off fireworks.
Erdogan and his party have won every election since the party came to power in 2002.