Hagia Sophia has witnessed many upheavals in its 1,500 year history, evolving from a cathedral to a mosque, then a museum.
In a landmark decision, Turkey's high court has ruled that its conversion into a museum in 1934 was unlawful - paving the way for the most visited monument in the country to be converted back to an Islamic place of worship.
The move, which threatens to upset Christians around the world, is not about creating more space for prayer as Istanbul has more than 3,000 mosques.
Rather, the decision reflects the wider societal struggle within Turkey between secularism and President Erdogan's religious conservatism.
Dozens of people who awaited the court’s ruling outside the Hagia Sophia jubilantly chanted “Allah is great!” when the news came out.
The religious group had contested the legality of the 1934 decision by the modern Turkish republic’s secular Government ministers and argued the building was the personal property of Ottoman Sultan Mehmet II, who conquered Istanbul in 1453.
The court ruled Hagia Sophia is the property of a foundation managing the Sultan’s assets and has opened it up to the public as a mosque.
Turkish officials have said opening Hagia Sophia to prayer will not stop tourists from visiting the site and have offered reassurance that the building's Christian icons will be preserved. However, historian Zeynep Ahunbay, who has worked on the conservation of Hagia Sophia for 27 years, doesn't see how that will be possible.
She said: "With the images of Madonna, mother of Christ, and other saints on the walls - do they accept to pray in the presence of these images? "It's a [UNESCO] world heritage site and I want it to be open to all nations and beliefs and accessible. If it becomes a mosque there are restrictions. . . There is already tension in Turkey because there is a reaction to these conservative people who make decisions as if we are an Islamic country," she said.
Turkey is overwhelmingly Muslim and this move to reclaim Hagia Sophia as a mosque is seen as a bid to boost Mr Erdogan's AK Party's sliding popularity polls.
BASSAM MICHAEL MADANY
"Turkey is overwhelmingly Muslim" is not an accurate statement. Almost half of Turkey's population are secular; living in the major cities of the country. They vote for the CHP (People's Republican Party) and resent Erdogan's attempt to re-Islamise Turkey. He tries to erase everything that relates to the Christian background of the land. Turkey's courts are no longer independent of the Government, and the role of the Army as a guardain for Ataturkian legacy has disappeared.