The first church on the site, of basilical form, was built near the Milion, that is, in the neighborhood of the Great Palace and Hippodrome, by Constantius II (not Constantine as often stated) and inaugurated in 360. It was known as the Great Church (Megale Ekklesia)—the name Hagia Sophia is first attested ca.430—and had the episcopal palace attached to its south side. Burned down by the supporters of John Chrysostom in 404, it was rebuilt, once again as a basilica, by Theodosios II and completed in 415. The only extant part of the Theodosian basilica is a colonnaded porch, probably the façade of the atrium rather than of the church itself .
The second Hagia Sophia was destroyed by fire during the Nika Revolt against Justinian I (Jan. 532). Rebuilding was started immediately, under the direction of the architects Anthemios of Tralles and Isidore of Miletos, and the new cathedral was inaugurated on 27 Dec. 537. An account of the construction and the technical difficulties that had to be overcome is given by Prokopios. In large part, Justinian’s church is still standing.
It is a domed basilica, that is, a combination of longitudinal and centralized planning, nearly square (78 × 72 m excluding the two narthexes), its nave covered by a dome 100 Byz. feet (31 m) in diameter and two semidomes, but at the same time clearly separated by rows of columns into three aisles, with galleries over the lateral aisles and narthex. The original dome collapsed in 558 and was rebuilt by Isidore the Younger some 7 m higher than the first one. The church, rededicated on 24 Dec. 562, was the subject of a descriptive poem by Paul Silentiarios.
The architectural conception of Anthemios and Isidore differed in some respects from the present form of the building. The dome, which may have continued the curvature of the pendentives, produced a more overwhelming impression from inside than the current steeper dome. The north and south tympanums appear to have been pierced by large windows, thus affording a more brilliant illumination. The exterior was unencumbered by buttresses. The liturgical fixtures are known in their post-562 form. They included a gold altar table surmounted by a ciborium; a projecting chancel screen of 12 columns; and, joined to the latter by an enclosed passage (solea), a lofty ambo. Most of these features as well as the top row of seats of the synthronon in the apse were sheathed in silver revetments.
The church was surrounded by subsidiary structures. To the west lay a colonnaded atrium with a fountain at its center; to the north the larger of two baptisteries (the smaller, still extant, being at the southwest) and, at the northeast corner, a circular sacristy (skeuophylakion); the south side was flanked by the patriarchal palace (built 565–77), a multistory building whose main apartments communicated with the south gallery of the church. The rooms situated at the south end of the west gallery, which preserve remnants of mosaic decoration, served as offices (sekreta) attached to the patriarchal complex. At the southeast corner of the church a raised passage connected Hagia Sophia to the Great Palace.
Hagia Sophia was naturally the liturgical center of the capital. Administratively it was joined to three other nearby churches, namely St. Irene, the Theotokos of the Chalkoprateia, and St. Theodore of Sphorakios; all four churches were served by the same clergy, whose establishment was limited by Justinian to 425, but which increased to 525 in the next century. Hagia Sophia also played an essential part in imperial ceremonial and had two rooms (metatoria) reserved for the emperor’s use. The itinerary of imperial processions in and out of Hagia Sophia is minutely described in the De ceremoniis.
The most important structural alterations of the church during the Byz. period were the following. Repairs after the earthquake of 869 may have included the rebuilding of the tympanums in their present form. In 989 the main west arch collapsed together with the west semidome and a portion of the dome; they were rebuilt by the Armenian architect Trdat. In 1317 massive exterior buttresses were added on the north and east sides of the building. In 1346 the east arch collapsed, bringing down the east semidome and one-third of the dome and destroying the ambo underneath; the damage was repaired by 1353 with the restricted means that were then available.
The marble and opus sectile decoration of the vertical surface of the walls is relatively well preserved. The mosaic decoration of Justinian’s church appears to have been largely nonfigural and much of it still survives in the vaulting of the narthex, side aisles, etc. The summit of the dome was occupied by a huge cross in a medallion. After Iconoclasm a program of figural mosaics was undertaken and part of it is preserved: an enthroned Virgin in the apse, two archangels in the bema arch, prophets and church fathers in the tympana. Narrative scenes are known to have existed in the gallery vaults (Baptism, Pentecost, Isaiah’s vision). Other preserved mosaics may be regarded as individual insets. They include a 10th-C. panel of the Virgin and Child flanked by Constantine I and Justinian I in the southwest vestibule; the enthroned Christ with a prostrate emperor (Basil I or Leo VI) at his feet in the lunette above the “Imperial Door”; the imperial portraits ( Alexander—P.A. Underwood, Constantine IX with Zoe, John II Komnenos with Irene) and the Deesis (late 13th C.) in the gallery. The Pantokrator in the main dome (which was restored in 1355) has disappeared. In 1989 the mosaics on the eastern arch, comprising the figures of John V Palaiologos, the Virgin Mary, and John the Baptist, as well as a Hetoimasia came to light.
In 1453 Hagia Sophia was converted into a mosque (Ayasofya Camii). Apart from the addition of four minarets, it underwent several repairs, the most important in 1573 and the following years, then in 1847–49, the latter carried out by the Swiss architects Gaspare and Giuseppe Fossati.