section_path: History/Foundation and expansion of Cairo
section_name: Foundation and expansion of Cairo
paragraph_text: Foundation and expansion of Cairo
  
  In 969, the Shi'a Isma'ili Fatimid empire conquered Egypt after ruling from Ifriqiya. The Fatimid general Jawhar Al Saqili founded a new fortified city northeast of Fustat and of former al-Qata'i. It took four years to build the city, initially known as al-Manṣūriyyah, which was to serve as the new capital of the caliphate. During that time, the construction of the al-Azhar Mosque was commissioned by order of the caliph, which developed into the third-oldest university in the world. Cairo would eventually become a centre of learning, with the library of Cairo containing hundreds of thousands of books. When Caliph al-Mu'izz li Din Allah arrived from the old Fatimid capital of Mahdia in Tunisia in 973, he gave the city its present name, Qāhirat al-Mu'izz ("The Vanquisher of al-Mu'izz"), from which the name "Cairo" (al-Qāhira) originates. The caliphs lived in a vast and lavish palace complex that occupied the heart of the city. Cairo remained a relatively exclusive royal city for most of this era, but during the tenure of Badr al-Gamali as vizier (1073–1094) the restrictions were loosened for the first time and richer families from Fustat were allowed to move into the city. Between 1087 and 1092 Badr al-Gamali also rebuilt the city walls in stone and constructed the city gates of Bab al-Futuh, Bab al-Nasr, and Bab Zuweila that still stand today.
  
  During the Fatimid period Fustat reached its apogee in size and prosperity, acting as a center of craftsmanship and international trade and as the area's main port on the Nile. Historical sources report that multi-story communal residences existed in the city, particularly in its center, which were typically inhabited by middle and lower-class residents. Some of these were as high as seven stories and could house some 200 to 350 people. They may have been similar to Roman insulae and may have been the prototypes for the rental apartment complexes which became common in the later Mamluk and Ottoman periods.
  
  However, in 1168 the Fatimid vizier Shawar set fire to unfortified Fustat to prevent its potential capture by Amalric, the Crusader king of Jerusalem. While the fire did not destroy the city and it continued to exist afterward, it did mark the beginning of its decline. Over the following centuries it was Cairo, the former palace-city, that became the new economic center and attracted migration from Fustat.
  
  While the Crusaders did not capture the city in 1168, a continuing power struggle between Shawar, King Amalric, and the Zengid general Shirkuh led to the downfall of the Fatimid establishment. In 1169, Shirkuh's nephew Saladin was appointed as the new vizier of Egypt by the Fatimids and two years later he seized power from the family of the last Fatimid caliph, al-'Āḍid. As the first Sultan of Egypt, Saladin established the Ayyubid dynasty, based in Cairo, and aligned Egypt with the Sunni Abbasids, who were based in Baghdad. In 1176, Saladin began construction on the Cairo Citadel, which was to serve as the seat of the Egyptian government until the mid-19th century. The construction of the Citadel definitively ended Fatimid-built Cairo's status as an exclusive palace-city and opened it up to common Egyptians and to foreign merchants, spurring its commercial development. Along with the Citadel, Saladin also began the construction of a new 20-kilometre-long wall that would protect both Cairo and Fustat on their eastern side and connect them with the new Citadel. These construction projects continued beyond Saladin's lifetime and were completed under his Ayyubid successors.