Originally built in AD 1010 by the Fatimid Khalifa (caliph) al-Hakim bi Amr Allah, this gigantic mosque was restored under the aegis of the Aga Khan, spiritual leader of the Isma'ili Shi'a sect.
Al-Hakim was, to put it nicely, an eccentric character. Some of the strangest edicts were declared during his caliphate, including a ban on mulokhia, a favorite Egyptian dish (he didn't care for it), and a ban on women's shoes, to prevent them from going out in public. Rumors began to circulate that he was claiming to be divine, creating extreme unrest among the populace. In order to quell the riots, he sent his main theologian, al-Darazi, to Syria (where he established the Druze religion), and then ordered his troops to attack Fustat, which at the time was the local town outside the royal city of al-Qahira. However, half his troops sided with the people, and the ensuing violence resulted in the burning of Fustat. He was given to riding around town on his donkey to ensure that his
orders were being obeyed. One night after riding off into the Muquattam hills, he disappeared, never to be seen again, although the Druze claim that he has vanished only temporarily and will return to lead them to victory.
Built outside the original walls of Cairo (those standing now were constructed in 1087), the mosque has seen varied usage during its lifetime. During the Crusades it held European prisoners of war, who built a chapel inside it. Salah al-Din (1137–93) tore the chapel down when he used it as a stable. For Napoléon's troops it was a storehouse and fortress. Under Muhammad 'Ali in the 1800s, part of it was closed off and used as a zawya (small Sufi school). By the end of the 19th century, until the establishment of the Museum of Islamic Arts in 1896, it was a repository for Islamic treasures.
Architecturally, the mosque does not compete among the finest in the city; the most significant element is its minarets, which were restored and reinforced by Baybars II in 1303, giving them that impressive trapezoidal base. Nevertheless, its scale and history are important, and its courtyard is large and breezy, making it a comfortable place to rest or meditate.