The Mamluks were a corps of slaves which went from being the elite bodyguards of the Ayyubid Caliphate founded by Saladin, to running Egypt for themselves. It lasted as an independent state for over 250 years, from 1250 to 1517 when Egypt was conquered by the Ottoman Empire. But the Mamluks survived.
By the 1630s, a Mamluk emir managed to become de facto ruler of the country. By the 1700s, the importance of the pasha (Ottoman governor) was superseded by that of the Mameluk beys, and it was even made official. Two offices, those of Shaykh al-Balad and Amir al-hajj – both offices held by Mameluks – represented the rulers of Egypt. In the name of the Ottoman Sultan, of course. It was only with the invasion of Egypt by Napoleon in 1799 that the Mamluk power center was permanently ended.