The Fatimid Caliphate's religious ideology originated in an Ismaʻili dawah (movement) launched in the ninth century in Salamiyah, Syria by the eighth Ismaili Imam, Ahmad al-Wafi (766–828). He claimed descent through Isma'il ibn Jafar, the seventh Ismaili Imam, from Fatimah and her husband ʻAli, the first Shiʻi Imam, whence his name al-Fāṭimiyy "the Fatimid". The eighth to tenth Ismaili Imams, (Ahmad al-Wafi, Muhammad at-Taqi (c. 813 – c. 840) and ʻAbdullāh al-Raḍī (died 881), remained hidden and worked for the movement against the rulers of the period.
Together with his son, the 11th Imam Abdullah al-Mahdi Billah (lived 873–934), in the guise of a merchant, made his way to Sijilmasa (now in Morocco), fleeing persecution by the Abbasid Caliphate, who found Ismaʻili beliefs heretical and also a political threat. According to legend, 'Abdullah and his son were fulfilling a prophecy that the Mahdi would come from Mesopotamia to Sijilmasa. They hid among the population of Sijilmasa, then an independent emirate, ruled by Prince Yasa' ibn Midrar (r. 884–909).
Abdullāh al-Mahdi's control soon extended over all of the Maghreb, an area consisting of the modern countries of Morocco, Algeria, Tunisia, and Libya, which he ruled from Mahdia. The newly built city of Al-Mansuriya,[a] or Mansuriyya (Arabic: المنصورية), near Kairouan, Tunisia, served as the capital of the Fatimid Caliphate during the rule of the Imams Al-Mansur Billah (r. 946–953) and Al-Mu'izz li-Din Allah (r. 953–975).
In 969 the Fatimid general Jawhar the Sicilian conquered Egypt, where he built near Fusṭāt a new palace city which he also called al-Manṣūriyya. Under Al-Mu'izz li-Din Allah the Fatimids conquered the Ikhshidid Wilayah (see Fatimid Egypt), founding a new capital at al-Qāhira (Cairo) in 969.
The name al-Qāhirah (Arabic: القاهرة), meaning "the Vanquisher" or "the Conqueror", referenced the planet Mars, "The Subduer", rising in the sky at the time when the construction of the city started. Cairo was intended as a royal enclosure for the Fatimid caliph and his army - the actual administrative and economic capitals of Egypt were cities such as Fustat until 1169. After Egypt, the Fatimids continued to conquer the surrounding areas until they ruled from Tunisia to Syria, as well as Sicily.
Under the Fatimids, Egypt became the centre of an empire that included at its peak parts of North Africa, Sicily, Palestine, Jordan, Lebanon, Syria, the Red Sea coast of Africa, Tihamah, Hejaz, Yemen, with its most remote territorial reach being Multan (in modern-day Pakistan).
Egypt flourished, and the Fatimids developed an extensive trade network both in the Mediterranean and in the Indian Ocean. Their trade and diplomatic ties, extending all the way to China under the Song Dynasty (r. 960–1279), eventually determined the economic course of Egypt during the High Middle Ages. The Fatimid focus on agriculture further increased their riches and allowed the dynasty and the Egyptians to flourish under the Fatimid rule. The use of cash crops and the propagation of the flax trade allowed Fatimids to import other items from various parts of the world.
Renovated Juyushi Mosque,Cairo
While the ethnic-based army was generally successful on the battlefield, it began to have negative effects on Fatimid internal politics. Traditionally the Berber element of the army had the strongest sway over political affairs, but as the Turkish element grew more powerful, it began to challenge this, and by 1020 serious riots had begun to break out among the Black African troops who were fighting back against a Berber-Turk Alliance.
By the 1060s, the tentative balance between the different ethnic groups within the Fatimid army collapsed as Egypt suffered an extended period of drought and famine. Declining resources accelerated the problems among the different ethnic factions, and outright civil war began, primarily between the Turks under Nasir al-Dawla ibn Hamdan and Black African troops, while the Berbers shifted alliance between the two sides. The Turkish forces of the Fatimid army seized most of Cairo and held the city and Caliph at ransom, while the Berber troops and remaining Sudanese forces roamed the other parts of Egypt.
By 1072, in a desperate attempt to save Egypt, the Fatimid Caliph Abū Tamīm Ma'ad al-Mustansir Billah recalled general Badr al-Jamali, who was at the time the governor of Acre, Palestine. Badr al-Jamali led his troops into Egypt and was able to successfully suppress the different groups of the rebelling armies, largely purging the Turks in the process. Although the Caliphate was saved from immediate destruction, the decade long rebellion devastated Egypt and it was never able to regain much power. As a result, Badr al-Jamali was also made the vizier of the Fatimid caliph, becoming one of the first military viziers ("Amir al Juyush", Arabic: امير الجيوش, Commander of Forces of the Fatimids) who would dominate late Fatimid politics. Al-Jam`e Al-Juyushi (Arabic: الجامع الجيوشي, The Mosque of the Armies), or Juyushi Mosque, was built by Badr al-Jamali. The mosque was completed in 478 H/1085 AD under the patronage of then Caliph and Imam Ma'ad al-Mustansir Billah. It was built on an end of the Mokattam Hills, ensuring a view of the Cairo city. This Mosque/mashhad was also known as a victory monument commemorating vizier Badr's restoration of order for the Imam Mustansir. As the military viziers effectively became heads of state, the Caliph himself was reduced to the role of a figurehead. Badr al-Jamali's son, Al-Afdal Shahanshah, succeeded him in power as vizier.
In the 1040s, the Berber Zirids (governors of North Africa under the Fatimids) declared their independence from the Fatimids and their recognition of the Sunni Abbasid caliphs of Baghdad, which led the Fatimids to launch the devastating Banū Hilal invasions of North Africa. After about 1070, the Fatimid hold on the Levant coast and parts of Syria was challenged first by Turkic invasions, then the Crusades, so that Fatimid territory shrank until it consisted only of Egypt. The Fatimids gradually lost the Emirate of Sicily over thirty years to the Italo-Norman Roger I who was in total control of the entire island by 1091.
The reliance on the Iqta system also ate into Fatimid central authority, as more and more the military officers at the further ends of the empire became semi-independent.
After the decay of the Fatimid political system in the 1160s, the Zengid ruler Nūr ad-Dīn had his general, Shirkuh, seize Egypt from the vizier Shawar in 1169. Shirkuh died two months after taking power, and rule passed to his nephew, Saladin. This began the Ayyubid Sultanate of Egypt and Syria.