In the year 330, Byzantion gained the status of the capital of the Roman Empire, rechristened as "Nova Roma" (New Rome) under the leadership of Emperor Constantine the Great. During this time Hagia Sophia emerged as a cornerstone, one of the four defining structures that framed the bustling main square of Constantinople. Just as the legislative, executive and entertainment power of the Eastern Roman Empire represented the Senate, the Imperial Palace, and the Hippodrome; the institution that represented the religious power was the Hagia Sophia.


The first Hagia Sophia, named “Megale Ekklesia (Great Church)” and commissioned by Constantine the Great, fell victim to conflicts and rebellion in 404. Emperor Theodosios II's attempt at rebuilding in 415 faced challenges, leading to its collapse during the Nika rebellion in 531 AD. The resilient spirit of Hagia Sophia prevailed, paving the way for Emperor Justinian to commission the third and final basilica in 532. The third basilica church, despite its limited architectural knowledge and construction technique facilities, was completed in 537 AD in a time period that can be called a world record, such as 5 years, 10 months, 10 days. The new church, built with materials brought from the stone and marble quarries in the imperial borders, and temple fragments and columns, became a beautiful architectural combination of Greek and Roman architecture.


The third Basilica, the current Hagia Sophia, was the world's largest building, rivalling the Egyptian pyramids for almost 1,000 years. Its dome, seemingly suspended in air, held the title of the largest and highest for a millennium. Built with Emperor-sealed bricks from Rhodes, it stands as a stunning blend of Greek and Roman architecture. Construction began in 532, and the church opened in 537. Emperor Justinian, at the opening, reportedly declared, "I have defeated you, Solomon," referencing the temple in Jerusalem.


Istanbul, prone to earthquakes, saw Hagia Sophia endure damages in three earthquakes (557, 869, 986) during the Byzantine period, requiring repairs. The Latin invasion (1204-1261) inflicted significant damage, leading to subsequent repairs under Byzantine rule. In 1317, during Andronikos II's reign, extensive repairs included external support with reinforced buttresses. However, these efforts were inadequate, and in 1346, a section of the dome in the east collapsed without apparent cause.


After serving as a church for over a millennium, Hagia Sophia was converted into a mosque following the conquest of Constantinople in 1453. While maintaining the main structure, various changes were made over time to adapt it for Islamic use.


The changed made during the time of Mehmed the Conqueror include a now-lost wooden minaret and mihrab, as well as a marble minbar. Icons were covered, crosses removed, and a bell in the steeple and the dome's cross were taken down. A college was constructed behind Hagia Sophia, and victory tokens and Islamic relics, including one of Prophet Muhammad's prayer rugs and Mehmed's conquest banners, adorned the mosque. All income from Mehmed's shops and properties was dedicated to the Hagia Sophia Foundation, established by the Conqueror himself.


In 1526, Bronze candlesticks, taken from the cathedral after the conquest of Budin during the reign of Suleiman the magnificent, were placed on both sides of the mihrab in Hagia Sophia. Selim II showed a keen interest in Hagia Sophia and during his time the mosque was protected from surrounding houses that posed a threat to its structure. Mimar Sinan intervened by constructing reinforced buttresses, preventing a potential collapse. A minaret, likely the one in the southeast corner, was added during this period. Additionally, tombs of Sultans and the royal family started being interred within Hagia Sophia.


In the era of Murad III, Hagia Sophia underwent several additions. Two minarets were constructed in the north, and a chair (qursi), minbar (pulpit), and mahfil (screened and elevated loge in a mosque) were introduced. Notably, two large monolithic marble cubes from Bergama, dating back to the First Age, were installed, forming a fountain within the mosque. Other Ottoman-era additions include a 12nd or 13rd century fountain excavated in front of the west gate, a sebil (public fountain) near the current south entrance, and a marble sebil attributed to Sultan Ibrahim in the southwestern outer corner of the courtyard.


In the 19th century, the Fossati Brothers embarked on an extensive renovation project from 1847-1849, reinforcing the structure, renewing ornamentations, and unveiling hidden mosaics. Some additional structures were also added, including large plates, a library, a kindergarten (sibyan school) in the courtyard, with an elegant fountain and a soup kitchen in the back. This meticulous restoration ensured the preservation of Hagia Sophia's historical and artistic legacy.


The Fossatis' dedication, exploring mosaics and repairing damages, culminated in the reopening of Hagia Sophia for the first Jumaah prayer of the month Ramadhan in 1849.