Erdogan appears to concede Istanbul defeat after Ankara loss

* Opposition mayoral candidate defeats AKP rival in Ankara

* Istanbul result close, Erdogan seems to concede defeat

* Erdogan described elections as "matter of survival" for Turkey (Adds Istanbul opposition candidate)

By Tuvan Gumrukcu and Ece Toksabay

ANKARA, March 31 (Reuters) - Turkey's Tayyip Erdogan suffered a severe setback on Sunday as his ruling AK Party lost control of the capital Ankara for the first time in a local election and he appeared to concede defeat in the country's largest city, Istanbul.

Erdogan, who has dominated Turkish politics since coming to power 16 years ago and ruled his country with an ever tighter grip, campaigned relentlessly for two months ahead of Sunday's vote, which he described as a "matter of survival" for Turkey.

But the president's daily rallies and overwhelmingly supportive media coverage narrowly failed to win over the country's capital or secure a clear result in Istanbul, as Turkey's economic downturn weighed heavily on voters.

"The people have voted in favour of democracy, they have chosen democracy," opposition leader Kemal Kilicdaroglu said, declaring that candidates for his secularist Republican People's Party (CHP) had taken Ankara and Istanbul from the AK Party and held their Aegean coastal stronghold of Izmir, Turkey's third largest city,

Defeat for Erdogan's Islamist-rooted party in Ankara was a significant blow for the president. Losing Istanbul, where he launched his political career and served as mayor in the 1990s, would be an even greater symbolic shock and a broader sign of dwindling support.

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. State-owned Anadolu Agency said the AKP would appeal in some districts of the capital.

In Istanbul, Turkish TV channels showed that AKP candidate and former Prime Minister Binali Yildirim had the narrowest of leads over his rival Ekrem Imamoglu - 4,000 votes out of 8 million counted - with 98.8 percent of ballot boxes opened.

Yildirim declared victory, but his claim was challenged by Imamoglu who said CHP data showed he had an unassailable lead.

In a speech to supporters in Ankara, Erdogan appeared to accept AKP defeat in Istanbul, although he maintained that most neighbourhoods in the city were held by his party. "Even if our people gave away the mayorship, they gave the districts to the AK Party," he said.

The party would appeal results wherever needed, he added.

"TURNING A PAGE"

Erdogan pledged that Turkey would now focus on its troubled economy in the run-up to national elections in 2023. "We have a long period ahead where we will carry out economic reforms without compromising on the rules of the free-market economy," he told reporters.