Muhammad Ali's rise to power occurred from 1803 to 1807 when the Albanian warlord Muhammad Ali seized power from the Ottoman Empire and the Mamluks of Egypt.
The British evacuation of Alexandria in March 1803, following the end of Napoleon Bonaparte's Egyptian Campaign, left a power vacuum in Egypt. The Mamluk Muhammad Bey al-Alfi took Minia and interrupted communication between Upper Egypt and Lower Egypt, intending on re-establishing Mamluk control of the country. The Ottoman governor Koca Husrev Mehmed Pasha was forced to disband his Albanian bashi-bazouks after being unable to pay all the men under his command, resulting in their leader Tahir Pasha leading a mutiny in Cairo. Tahir took control of the citadel and bombarded the pasha's forces, besieging the governor's palace until Koca Pasha fled with his women, servants, and regular troops to Damietta along the Nile. Tahir then assumed control of the government, but his inability to pay his Turkish troops led to mutinying Turks assassinating him and burning and plundering his governor's palace. The Mamluks proceeded to alternate between supporting the Albanians and Turks as the two factions engaged in a violent power struggle.
Albanian regimental commander Muhammad Ali replaced Tahir Pasha, and he allied with the Mamluk leaders Ibrahim Bey and Osman Bey al-Bardisi. Meanwhile, Koca Pasha fortified himself at Damietta and the Turkish troops near Cairo acclaimed Muftizade Ahmed Pasha as their new governor. Muhammad Ali refused to surrender Cairo to him, and he forced the Mamluks out of Giza. Muhammad Ali besieged Muftizade Ahmed Pasha in the Cairo Citadel and forced him to surrender, and the Turkish mutineers who had killed Tahir Pasha were put to death.
Muhammad Ali gave control over the Cairo Citadel to his Mamluk allies, who marched on Damietta and captured Husrev. The bashi-bazouks sacked Damietta, but Husrev was treated with respect. Days later, Trabluslu Ali Pasha arrived in Alexandria to take over the governorship of Egypt, taking control of the remaining Turkish forces. Muhammad Ali and al-Baridsi descended on Rosetta and captured the city before the Mamluks' extortionate taxes on peasants to pay their soldiers - together with an insufficient flood of the Nile - led to great scarcity, riots, and violence, with the bashi-bazouks under little or no control in the capital. The Ottomans soon won over the Mamluk beys after promising them annual pensions, causing a rift between them and their Albanian allies. Trabluslu Ali Pasha advanced in Cairo with 3,000 men, but the Albanians defeated the Turks at Shalakan. The Turkish army deserted Trabluslu at Zufeyta, handing him over to the Mamluks before returning to Syria; Trabluslu was later murdered by his own men.
On 12 February 1804, al-Alfi returned from Britain, causing the Mamluks to split into al-Alfi and al-Bardisi factions. Meanwhile, Muhammad Ali recaptured Giza, and al-Alfi was ambushed by the Albanians near Manfif on his way to Cairo and was forced to flee to take shelter among the Bedouin. At the same time, al-Bardisi's taxes in Cairo led to a Cairene rebellion. Muhammad Ali made concessions to calm the public, winning his Albanians popularity among the Cairenes, and al-Bardisi and Ibrahim Bey were chased out of Cairo on 12 March 1804; the Mamluks were also forced to abandon the Citadel. However, Muhammad Ali's appointed governor Mahommed Khosrev Pasha was assassinated one and a half days later, resulting in chaos in Cairo. The Albanians invited Hurshid Ahmed Pasha to assume the reins of government, while al-Bardisi's Mamluks ravaged the countryside. Muhammad Ali battled al-Baridi's forces south of Cairo and al-Alfi's forces at the two fortresses of Tur, and Hurshid Ahmed Pasha brought in 3,000 Kurdish deli cavalry from Syria to strengthen himself against the Albanians. However, the delis turned on Hurshid Ahmed Pasha, and the Turks appointed Muhammad Ali governor of Jeddah in a bid to lure him away from Egypt. However, Muhammad Ali instead seized power in Egypt, and he captured the citadel from Hurshid Ahmed Pasha. Muhammad Ali Pasha was appointed the new governor of Egypt, while Hurshid Ahmed Pasha was recalled to Alexandria. Muhammad Ali went on to defeat the Mamluk siege of Damanhour, and, soon after, an Ottoman fleet arrived at ABukir Bay to confirm Muhammad Ali's rule over Egypt.
Now confirmed as Governor of Egypt, Muhammad Ali faced off against the Mamluk beys of the countryside, Hurshid Ahmed Pasha's siladar army, and Albanian deserters. The Mamluks failed to take Cairo in August 1805, and Muhammad Ali executed several captured beys and send 83 heads to Constantinople to boast that the Mamluk chiefs were utterly destroyed. The Ottomans decided to reinstate 24 Mamluk beys with al-Alfi at their head, sending Salih Pasha with 3,000 regular troops to Egypt on 1 July 1806. Muhammad Ali refused to depart for Salonika as ordered, instead persuading the Albanian chiefs to swear personal allegiance to him. After al-Bardisi died and al-Alfi's troops revolted and mutinied while besieging Damanhour (al-Alfi died of a sudden illness on 30 January 1807), Muhammad Ali was relieved of his two most formidable enemies.
On 17 March 1807, a British fleet carrying 5,000 troops appeared off Alexandria, and the people warmly received the British, who reached out to the other Mamluk beys. The British entered Rosetta without opposition before being ambushed, forcing them to retreat to Aboukir and Alexandria. General Patrick Wauchope was killed, and Muhammad Ali won the support of several surviving Mamluks in expelling the British. The British were besieged in Hamad and ultimately forced to surrender, and many of the British dead had their heads exposed on stakes in Cairo.
The Mamluks soon experienced divisions between pro-British and pro-Albanian factions, but the British evacuated Alexandria on 14 September 1807. From then until 1811, the Mamluks gradually went over to Muhammad Ali. However, Muhammad Ali oversaw the massacre of all 470 Mamluks who gathered at the Citadel of Cairo on 1 March 1811, removing his opposition through a swift betrayal. Muhammad Ali issued orders for every governor to engage in the indiscriminate massacre of the Mamluks throughout Egypt, and the heads of the beys were sent to Istanbul. A remnant of the Mamluks fled to Nubia, and tranquility was restored to Egypt. Ibrahim Bey was among those forced to flee to Dongola, where he died in 1816. In 1820, the Egyptians invaded Nubia, defeating the remaining Mamluks.