Sinan Ulgen, director of the Istanbul-based Edam think tank, said "the surprising outcome" was due to voters wanting to punish the ruling party over the "depth of an economic malaise".
Skyrocketing inflation has left many Turkish households struggling to afford basic goods.
AKP supporters opted to stay away from the ballot stations or voted for other parties, Mr Ulgen said.
"Turnout was relatively low compared to past elections," he said.
Opposition Republican People's Party (CHP) supporters celebrate outside the main municipality building in Istanbul
AFP via Getty Images
"There were cross-party shifts in the vote, which did not happen in the national elections because of stronger ideological attachments. This time around, the economy prevailed over identity."
About 61 million people, including more than a million first-time voters, were eligible to cast ballots for all metropolitan municipalities, town and district mayorships as well as neighbourhood administrations.
Turnout was about 76%, according to the state-run Anadolu Agency, compared to 87% last year.
Analysts said a strong showing for Mr Erdogan's party would have hardened his resolve to usher in a new constitution - one that would reflect his conservative values and allow him to rule beyond 2028 when his current term ends.
Mr Erdogan, who has presided over Turkey for more than two decades - as prime minister since 2003 and president since 2014 - has been advocating for a new constitution that would put family values at the forefront.
Some 594,000 security personnel were on duty across the country to ensure the vote goes smoothly.
Nevertheless, one person was killed and 11 others hurt in the city of Diyarbakir where a dispute over the election of a neighbourhood administrator turned violent, the state-run Anadolu Agency reported.