The name Fatimid is derived from the name of daughter of the Prophet Muhammad, Fatima az-Zahra, and her husband, Ali, a cousin of the Prophet. The dynasty and its followers belonged to the Shiite branch of Islam and to a sect called Isma'ili. The dynasty was founded when a local leader declared himself al-Mahdi, the "divinely guided one" and the khalifa or, imam. He legitimized his claim by his descent from the Prophet by way of Prophet's daughter Fatima Zahra and her husband Ali ibn Abu Talib, who was a cousin of the Prophet. This happened in Kairwan, a city located in the center of Tunisia but soon his control extended over all of central Maghreb, an area consisting of the modern countries of Morocco, Algeria, Tunisia and Libya.
The Fatimids entered Egypt in 972 where they founded a new capital at al-Qahira (Cairo), meaning "the Triumphant". They continued to conquer the surrounding areas until they ruled from Tunisia to Syria, and even crossed over into Sicily.
Unlike other governments in the area, Fatimid advancement in state offices was based more on merit than on heredity, bribes, and devious machinations. Members of other branches of Islam, like the Sunnis, were just as likely to be appointed to government posts as Shiites. Tolerance was extended even to non-Muslims, like Christians and Jews who occupied the highest levels of government based solely on ability.
The empire continued to grow and flourish until Caliph Al-Hakim whose reign began auspiciously with the building of the great mosque between Bab Al-Futuh and Bab An-Nasr in Cairo (the Al-Hakim Mosque). Breaking with tradition, he mingled with his the people to feel the pulse of his subjects. Gradually, however, he grew more insane until he executed anyone he didn't like and promulgated arbitrary regulations, like outlawing the manufacture of women's shoes or prohibiting working during the day and sleeping at night. His death is shrouded in mystery but some declared that he was divine and had ascended to a spiritual realm. Believers in this tradition became known as the Druze who still exist in Lebanon, Syria, Jordan and Palestine.
After about 1060 Fatimid territory shrunk until it consisted only if Egypt. On the death of the last Fatimid caliph in 1171, Saladin joined Egypt to the Abbasid Caliphate and Egypt returned to the Sunni branch of Islam, bringing the Faimid dynasty to an end.