In 969, led by General Gawhar al-Siqilli, the Fatimid Caliphate conquered Egypt from Tunisia and established a new fortified city northeast of Fustat. It took four years for Jawhar to build the city, initially known as al-Man??riyyah, which later took its Modern name, Al-Qahira (Cairo) which was to serve as the new capital of the caliphate. During that time, Jawhar also commissioned the construction of al-Azhar Mosque, which developed into the third-oldest university in the world. Cairo would eventually became a centre of learning, with the library of Cairo containing hundreds of thousands of books. When Caliph al-Mu'izz li Din Allah finally arrived from the old Fatimid capital of Mahdia in Tunisia in 973, the city was given its present name, al-Qahira ("The Victorious"), in reference to the caliph.
The Cairo Citadel, seen above in the late 19th century, was built between 1176 and 1183
For nearly two hundred years after Cairo was established, the administrative centre of Egypt remained in Fustat. However in 1168 the Fatamids, under the leadership of Vizier Shawar, set fire to Fustat to prevent Cairo's capture by the Crusaders. Egypt's capital was permanently moved to Cairo, which eventually expanded to include the ruins of Fustat and the previous capitals of al-Askar and al-Qatta'i. While the Fustat fire successfully protected the city of Cairo, a continuing power struggle between Shawar, King Amalric I of Jerusalem, and Syrian general Shirkuh led to the downfall of the Fatimid establishment.
In 1169 Saladin was appointed as the new vizier of Egypt and two years later he would seize 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 Abbasids, who were based in Baghdad. During his reign, Saladin also constructed the Citadel, which served as the seat of Egyptian government until the mid-19th century.
In 1250 slave soldiers, known as the Mamluks, seized Egypt and like many of their predecessors established Cairo as the capital of their new dynasty. Continuing a practice started by the Ayyubids, much of the land occupied by former Fatimid palaces was sold and replaced by newer buildings. Construction projects initiated by the Mamluks pushed the city outward while also bringing new infrastructure to the centre of the city. Meanwhile, Cairo flourished as a centre of Islamic scholarship and a crossroads on the spice trade route between Europe and Asia. By 1340, Cairo had a population of close to half a million, making it the largest city west of China.