It is actually not a mosque right now, a museum instead. Hagia Sophia was built in th 6th century by Byzantium as a cathedral, and it was converted into a mosque by the Ottomans after overtaking Istanbul. When the Turkish Republic was founded in the 20th century, Hagia Sophia started to serve as a museum. Just a side note