The church was built on the site of several earlier churches and places of worship dating back to the days when it was the necropolis of the Roman town of Serdica. In the 2nd century CE, it was the location of a Roman theatre. Over the next few centuries, several other churches were constructed, only to be destroyed by invading forces such as the Goths and the Huns. The basic cross design of the present basilica, with its two east towers and one tower-cupola, is believed to be the fifth structure to be constructed on the site and was built during the reign of Byzantine Emperor Justinian I in the middle of the 6th century (527-565 CE). It is thus a contemporary of the better-known Saint Sophia church in Constantinople.
During the Second Bulgarian Empire (spanning the 12th to 14th centuries), the structure acquired the status of a metropolitan church. In the 14th century, the church gave its name to the city (Hagia Sophia meaning "holy wisdom" in Greek). In the 16th century, during Ottoman rule, the church was converted into a mosque: the original twelfth-century frescoes were destroyed and minarets were added. In the 19th century two earthquakes destroyed one of the minarets and the mosque was abandoned. Restoration work was begun after 1900.
The Hagia Sophia Church is now one of the most valuable pieces of Early Christian architecture in Southeastern Europe. The present building is a cross basilica with three altars. The floor of the church is covered with complex Early Christian ornamental or flora and fauna-themed mosaics. The Hagia Sophia Church stands in the middle of an ancient necropolis and many tombs have been unearthed both under and near the church. Some of the tombs even feature frescoes.