) was a Greek Orthodox Christian patriarchal basilica (church), later an imperial mosque, and is now a museum (Ayasofya Müzesi) in Istanbul, Turkey.
From the date of its construction in 537 AD, and until 1453, it served as an Eastern Orthodox cathedral and seat of the Patriarch of Constantinople, except between 12, when it was converted by the Fourth Crusaders to a Roman Catholic cathedral under the Latin Empire.
Justinian chose physicist Isidore of Miletus and mathematician Anthemius of Tralles as architects; Anthemius, however, died within the first year of the endeavor.
The construction is described in the Byzantine historian Procopius' On Buildings (Peri ktismatōn, Latin: De aedificiis).
Islamic features—such as the mihrab, minbar, and four minarets—were added.
It remained a mosque until 1931 when it was closed to the public for four years.
The Byzantine architecture of the Hagia Sophia served as inspiration for many other Ottoman mosques, such as the aforementioned mosque, the Şehzade Mosque, the Süleymaniye Mosque, the Rüstem Pasha Mosque and the Kılıç Ali Pasha Complex.
Like other churches throughout Christendom, the basilica offered sanctuary from persecution to outlaws.
The Patriarch of Constantinople John Chrysostom came into a conflict with Empress Aelia Eudoxia, wife of the emperor Arcadius, and was sent into exile on 20 June 404.
During the subsequent riots, this first church was largely burned down. A second church on the site was ordered by Theodosius II, who inaugurated it on 10 October 415.
The basilica with a wooden roof was built by architect Rufinus.
A fire started during the tumult of the Nika Revolt and burned the second Hagia Sophia to the ground on 13–14 January 532.
It was designed by the Greek geometers Isidore of Miletus and Anthemius of Tralles.