The landmark Hagia Sophia museum in Istanbul will be controversially turned into a mosque, it's been announced.

Turkey's president Recep Tayyip Erdogan revealed the move this week ahead of local elections this weekend.

Hagia Sophia, called Ayasofya in Turkey, has been a church and a mosque in the past.

For nearly 900 years — after being built in 537 by the Byzantine Emperor Justinian — it was a Greek Orthodox Christian cathedral. From 1453 until 1931 it was one of Islam's greatest mosques, under the Ottoman Empire.

Hagia Sophia became a museum in 1934, by a decree from Mustafa Kemal Ataturk, the founder of modern Turkey.

This secular status allows worshippers of all religions to enjoy the building.

The status often creates tensions between Muslims and Christians, because the readings of the Koran or collective prayers are sometimes held in the Hagia Sophia.

But Erdogan said on Wednesday that it had been a "very big mistake" to turn it into a museum.

Turkey is holding municipal elections on March 31 and the announcement is believed to be part of Erdogan's campaign for his party, the Justice and Development Party (AKP).

The change of status will be discussed after the elections, the Turkish president said.

In 2013, Erdogan said he would not consider changing Hagia Sophia’s status. But he said that "there is a demand" now among the Turkish people for the Hagia Sophia to be turned into a mosque again.

Erdogan's decision risks angering Greece, Turkey's neighbour and historical adversary. The Greek PM Alexis Tsipras visited the Hagia Sophia after meeting with Erdogan last month.