The Ayyubid dynasty (الأيوبيون al-Ayyūbīyūn; ئەیووبیەکان, Eyûbiyan), also known as the Ayyubid Empire, was the founding dynasty of the medieval Sultanate of Egypt established by Saladin in 1171, following his abolition of the Fatimid Caliphate of Egypt. A Sunni Muslim of Kurdish origin, Saladin had originally served Nur ad-Din of Syria, leading Nur ad-Din's army in battle against the Crusaders in Fatimid Egypt, where he was made Vizier. Following Nur ad-Din's death, Saladin was proclaimed as the first Sultan of Egypt by the Abbasid Caliphate, and rapidly expanded the new sultanate beyond the frontiers of Egypt to encompass most of the Levant (including the former territories of Nur ad-Din), in addition to Hijaz, Yemen, northern Nubia, Tarabulus, Cyrenaica, southern Anatolia, and northern Iraq, the homeland of his Kurdish family. By virtue of his sultanate including Hijaz, the location of the Islamic holy cities of Mecca and Medina, he was the first ruler to be hailed as the Custodian of the Two Holy Mosques, a title that would be held by all subsequent Sultans of Egypt until the Ottoman conquest of 1517. Saladin's military campaigns in the first decade of his rule, aimed at uniting the various Arab and Muslim states in the region against the Crusaders, set the general borders and sphere of influence of the Sultanate of Egypt for the almost three and a half centuries of its existence. Most of the Crusader states, including the Kingdom of Jerusalem, fell to Saladin after his victory at the Battle of Hattin in 1187. However, the Crusaders reconquered the coast of Palestine in the 1190s.
After Saladin's death in 1193, his sons contested control of the sultanate, but Saladin's brother al-Adil ultimately became the Sultan in 1200. All of the later Ayyubid Sultans of Egypt were his descendants. In the 1230s, the emirs of Syria attempted to assert their independence from Egypt and the Ayyubid realm remained divided until Sultan as-Salih Ayyub restored its unity by subduing most of Syria, except Aleppo, by 1247.