Istanbul (CNN) Turkey's President Recep Tayyip Erdogan is facing a major political setback after his party lost control of the capital, Ankara, in a keenly fought local elections battle.

Preliminary results also showed the opposition narrowly ahead of the President's Justice and Development Party (AKP) in Istanbul, the country's largest city.

The results, if confirmed, will be a blow to Erdogan, who has dominated Turkish politics since becoming Prime Minister in 2003.

In Ankara, the opposition People's Republican Party (CHP) won more than 50% of votes while the AKP trailed on around 47%, state news agency Anadolu said. It is the first time in 25 years that the Islamist party has lost its grip on the capital.

Electoral officers count ballots at a polling station in Istanbul on March 31.

In Istanbul, the result was too close to call on Monday. According to Anadolu, CHP received 48.79% of votes, narrowly ahead of the AKP with 48.51%. Turkey's Supreme Election Council said that the results from 84 ballot boxes have not yet been included in the final count as there were objections. Both parties claimed victory in Istanbul, Anadolu reported.

Read More