The Küçük Ayasofya Mosque is identified as the Church of Sts. Sergius and Bacchus, constructed by Justinian I (527-565) following his ascension to the throne and is often considered the pre-cursor to the Great Church of Hagia Sophia. It was built inside the sea walls along the Sea of Marmara and stood in close proximity to the Hormisdas Palace, Justinian's residence prior to his enthronement. Historical resources show that the church dedicated to the Sts. Sergius and Bacchus was built adjoining the north wall of an existing basilica dedicated to the Sts. Peter and Paul. The two churches shared a courtyard to the west and were surrounded by monastery buildings managed by the Monophysites.
Hüseyin Aga, the chief officer of the Ottoman Palace during the rule of Bayezid II (1481-1512), converted the Church of Sergius and Bacchus into a mosque. He added the Ottoman narthex and built twenty-four zawiya cells enclosing the courtyard of the new complex, which he endowed with income from a nearby public bath and two hans near the Hagia Sophia. His tomb (türbe), built after his execution in 1510, lies in the walled cemetery that wraps around the north and east sides of the former church. Grandvizier Ahmed Pasa added an ablution fountain (sadirvan) and a primary school (mekteb) in 1740; the fountain was later removed in 1938. Damaged in the earthquakes of 1648 and 1763, the complex was repair by Mahmud II in 1831. If anything had remained from adjoining Church of Sts. Peter and Paul, it was removed during the construction of a railroad passing immediately to the south of the mosque in the 1860s, transforming the topography of the site. The architecture of the former church, despite modifications to its doors and windows, has largely remained intact. The Küçük Ayasofya was included in the annual list of the World Monuments Watch "100 Most Endangered Sites" in 2002.
The complex is entered through three gates, north, south and west, which lead into a courtyard enclosed by the U-shaped zawiya on three sides. An inscriptive plaque located above the northern gate bears a saying of the Prophet. Located to the east of the courtyard, the mosque is entered through a five-bay classical Ottoman portico that precedes the narthex. Its central plan is composed of an octagon inscribed in a rectangle; the domed octagonal nave is outlined by a continuous gallery on two floors, which envelops the nave to the north, west and south. The galleries terminate on either end of an apsidal sanctuary projecting to the east.
Composed of sixteen ribs with eight windows, the nave dome is supported on eight wide arches that fall on eight heavy piers forming an octagon. The space between the piers is spanned by twenty-eight marble columns, two in each bay with the exception of the sanctuary, that form the double-story gallery. The upper gallery columns are interlaced with small arches and wooden balustrades. Columns at the four corners of the nave are arranged to form semi-circular niches that are crowned with semi-domes at the upper gallery level. The nave is elaborately detailed with carved capitals, and the gallery entablature-inscribed with a poetic praise of Justinian and his wife, Theodora-has a delicate contour.
To the west, the gallery joins an unadorned double-story narthex, separated only by a series of columns and piers. Three small bays, placed along the southern gallery, may have led into the adjoining Church Sts. Peter and Paul. This wall, as seen from the outside, is indeed the northern wall of the latter church that remains incorporated into the neighboring structure. The mosque has a single minaret on the southwest corner, which dates from 1955.