The history of Egypt under the Muhammad Ali Pasha dynasty (1805–1953) spanned the later period of Ottoman Egypt, the Khedivate of Egypt under British patronage, and the nominally independent Sultanate of Egypt and Kingdom of Egypt, ending with the Revolution of 1952 and the formation of the Republic of Egypt.
The process of Muhammad Ali's seizure of power was a long three way civil war between the Ottoman Turks, Egyptian Mamluks, and Albanian mercenaries. It lasted from 1803 to 1807 with the Albanian Muhammad Ali Pasha taking control of Egypt in 1805, when the Ottoman Sultan acknowledged his position. Thereafter, Muhammad Ali was the undisputed master of Egypt, and his efforts henceforth were directed primarily to the maintenance of his practical independence.
Ottoman-Saudi war in 1811–18 was fought between Egypt under the reign of Muhammad Ali (nominally under Ottoman rule) and the Wahabbis of Hijaz.
When Wahabis captured Mecca in 1802, the Ottoman sultan ordered Muhammad Ali of Egypt to start moving against Wahabbis to re-conquer Mecca and return the honour of the Ottoman Empire.
Acknowledging the sovereignty of the Ottoman Sultan, and at the commands of the Ottoman Porte, in 1811 Muhammad Ali dispatched an army of 20,000 men (and 2,000 horses) under the command of his son Tusun, a youth of sixteen, against the Saudis in the Ottoman–Saudi War. After a successful advance this force met with a serious repulse at the Battle of Al-Safra, and retreated to Yanbu. In the end of the year Tusun, having received reinforcements, again assumed the offensive and captured Medina after a prolonged siege. He next took Jeddah and Mecca, defeating the Saudi beyond the latter and capturing their general.