Muhammad Ali rose to power in Egypt following a long, three-way civil war between the Ottoman Empire, Mamluks who had ruled Egypt for centuries, and Albanian mercenaries in the service of the Ottomans. The conflict ended in victory for the Albanians (from Rumelia) led by Ali.

The struggle occurred following the French invasion of Egypt by Napoleon. After the French were defeated, a power vacuum was created in Egypt. The Mamluks had governed Egypt before the French invasion and still retained power in the region. However, Egypt was officially a part of the Ottoman Empire and many Ottoman troops who had been sent to evict the French were still present.

Albanians under Tahir rise and seize Cairo from Hüsrev Pasha In March 1803, the British evacuated Alexandria, leaving a power vacuum in Egypt. Muhammad Bey al-Alfi (aka Alfi Bey) (1751–1807) had accompanied the British to lobby them to help restore the power of the Mamluks. In their attempts to return to power, the Mamluks took Minya and interrupted communication between Upper and Lower Egypt. About six weeks later, Koca Hüsrev Mehmed Pasha, the Ottoman governor of Egypt, was unable to pay all the troops under his command, so he attempted to disband his Albanian (Arnaut) bashi-bazouks without pay in order to be able to pay his regular Turkish soldiers.Inalcık, Halil. Trans. by Gibb, H.A.R. The Encyclopaedia of Islam, New Ed., Vol. V, Fascicules 79-80, pp. 35 f. "Khosrew Pasha". E.J. Brill (Leiden), 1979. Accessed 13 September 2011. The Albanians refused to disband and instead surrounded the house of the defterdar (finance minister), who appealed in vain to Hüsrev Pasha to satisfy their claims. Instead, the pasha commenced an artillery bombardment from batteries located in and near his palace on the insurgent soldiers who had taken the house of the defterdar, located in the Azbakeya. The citizens of Cairo, accustomed to such occurrences, immediately closed their shops and armed themselves. The tumult in the city continued all day, and the next morning, troops sent by Hüsrev Pasha failed to quell it.

The Albanian commander, Tahir Pasha, then returned to the citadel, gaining admittance through an embrasure, and from there began a counter bombardment of the pasha's forces over the roofs of the intervening houses. Soon thereafter, Tahir descended with his guns to the Azbakeya and then laid close siege to the governor's palace. The following day, Koca Hüsrev Mehmed Pasha fled with his women, servants, and regular troops to Damietta along the Nile.

Tahir then assumed control of the government, but within 23 days encountered trouble due to his own inability to pay all of his forces. This time, it was Turkish troops who went without pay, and they in turn mutinied and assassinated him. During the course of the mutiny, the governor's palace was burnt and plundered. A desperate, prolonged, and confusing conflict then ensued between the Albanians and Turks, with the divided Mamluks oscillating between the two factions or attempting to regain power themselves.

Muhammad Ali assumes control and captures Ahmed Pasha Tahir was replaced as commander of the Albanians by Muhammad Ali, one of the regimental commanders. Fearing for his position with the Ottomans, he entered into an alliance with the Mamluk leaders Ibrahim Bey and Osman Bey al-Bardisi.

With Hüsrev Pasha fortifying himself at Damietta, the Turkish troops in the vicinity of Cairo acclaimed Muftizade Ahmed Pasha, the Ottoman mayor of Medina (and previously Damietta), as their new governor. Muhammad Ali, however, refused to surrender Cairo to him. In reordering his forces to meet the new threat, he also removed the Mamluks from Giza, where they had been invited by his predecessor, Tahir.

Muftizade Ahmed Pasha established himself at the mosque of Baybars, which the French had converted into a fortress, but was eventually besieged by Muhammad Ali and his Albanian troops in the citadel of Cairo and compelled to surrender. Among the prisoners, those Turkish troops who had been involved in the assassination of Tahir Pasha were put to death.

Capture of Hüsrev and Damietta Muhammad Ali gave control over the Cairo citadel to his Mamluk allies. Soon after, they marched against Hüsrev Pasha, who had been joined by a considerable number of Turks in a well-fortified position at Damietta. Hüsrev was defeated, captured, and brought to Cairo by the Albanians. The bashi-bazouks sacked Damietta, but Hüsrev was treated with respect.

Trabluslu Ali Pasha attempts to regain control Days later, Trabluslu Ali Pasha landed at Alexandria with a firman from the Ottoman Porte appointing him the new governor of Egypt, and assumed control of the remaining Turkish forces. He threatened the Mamluk beys, now virtual masters of Upper Egypt, as well as of the capital and nearly all of Lower Egypt. Muhammad Ali and his Mamluk ally, al-Bardisi, therefore descended on Rosetta, which had fallen into the hands of a brother of Trabluslu Ali Pasha. The town and its commander were successfully captured by al-Bardisi, who then proposed to proceed against Alexandria; his troops, however, demanded back-pay which he was unable to provide. During this delay, Trabluslu Ali Pasha destroyed the dykes between the lakes of Aboukir and Mareotis, creating a moat around Alexandria. Unable to proceed with operations against Alexandria, Al-Bardisi and Muhammad Ali returned to Cairo.

The troubles of Egypt were exacerbated by an insufficient flood of the Nile, resulting in great scarcity, aggravated by the onerous taxation the Mamluk beys were forced to resort to in order to pay their troops. Riots and violence continued in the capital, with the bashi-bazouks under little or no control.

Meanwhile, Trabluslu Ali Pasha had been behaving with brutality towards the French in Alexandria. He received written instructions from the Ottoman sultan, which in an effort to sow dissension and mistrust between Muhammad Ali Pasha and his Mamluk allies, he sent to Cairo and caused to be circulated there. The Ottoman sultan announced that the Mamluk beys could live peaceably in Egypt with annual pensions of fifteen purses and other privileges, provided the government returned to the hands of the Turkish governor. To this many of the beys assented, and in the process opened a rift with Muhammad Ali Pasha and the Albanians. The Mamluks had already been suspicious of their Albanian allies, having previously intercepted letters addressed to them from Trabluslu Ali Pasha, endeavoring to win their alliance as well.

Trabluslu Ali Pasha advanced towards Cairo with 3,000 men to discuss his resumption of control. The forces of the beys still with Muhammad Ali Pasha and their Albanian allies advanced to meet Trabluslu Ali Pasha at Shelqan, forcing the Ottoman governor to fall back on a place called Zufeyta.

At this point, the Albanians managed to seize Trabluslu Ali Pasha's transport boats, capturing soldiers, servants, ammunition, and baggage. They then demanded to know why he had brought such a large host with him, contrary to both custom and a prior warning to not do so. Finding his advance blocked, reluctant to retreat with his forces to Alexandria, and being surrounded by the enemy in any case, Trabluslu Ali Pasha attempted to give battle, but his men refused to fight. He therefore abandoned his troops and went over to the camp of the Mamluk beys. His army was eventually allowed to retire to Syria.

With Trabluslu Ali Pasha in the hands of the beys, a horseman was seen to leave his tent one night at full gallop, and it was discovered that he bore a letter to Osman Bey Hasan, the governor of Kine (Kucuk Kine, Turkey). This gave the Mamluks a welcome pretext to rid themselves of him. Trabluslu Ali Pasha was sent under an escort/ guard of forty-five men towards the Syrian frontier; about a week later, news was received that during a skirmish with some of his own soldiers, he had fallen mortally wounded.

Return and flight of al-Alfi The death of Trabluslu Ali Pasha produced only temporary tranquility. On February 12, 1804, The Mamluk leader Muhammad Bey al-Alfi returned from the United Kingdom, splitting the Mamluks into two parties, one gathered around al-Alfi and the other around al-Bardisi, the latter having by then gained an ascendency among the Mamluks. The guns of the citadel and of the palace were fired three times each in al-Alfi's honor at news of his return, but preparations were simultaneously begun to oppose him before he arrived in Cairo.

Al-Alfi's partisans gathered opposite Cairo and held nearby Giza, when Husain Bey, one of al-Alfi's relatives, was assassinated by emissaries of al-Bardisi. Muhammad Ali Pasha seized upon this as a pretext to restore order, and took possession of Giza, which was given over to his troops to pillage.

Unaware of these events, al-Alfi embarked at Rashid and made his way to Cairo. Encountering a party of Albanians south of the town of Manfif, he was surprised in an ambush and only escaped with difficulty. Al-Alfi then made his way to the eastern branch of the Nile, but the region had become dangerous and he fled to the desert. There he had several close escapes and at last secreted himself among a tribe of Bedouin Arabs at Ras al-Wgdi.

Al-Bardisi and the Albanians fall out In the meantime, the fortunes of Al-Alfi's main Mamluk opponent, Al-Bardisi, began to decline. In order to satisfy the Albanian troops' demands for pay, he gave orders to levy heavy contributions from the citizens of Cairo. That roused the citizenry to open rebellion. The Albanians, alarmed for their safety, assured the populace that they would not allow the public order to collapse, and Muhammad Ali issued a proclamation to that effect and offered other concessions to calm the public.

Although their demands for pay had been the cause for Al-Bardisi's onerous levies that led to the public disturbances, Muhammad Ali Pasha's proclamation and concessions resulted in the Albanian forces gaining in popularity amongst the citizens, at the expense of the Mamluks. They soon took advantage of the opportunity. Three days later (March 12, 1804) the Albanians attacked the houses of al-Bardisi, as well as that of the aged Mamluk leader Ibrahim Bey. Both barely managed to escape. Upon hearing of the attack on their leaders' houses, the Mamluks in the Cairo citadel opened an artillery bombardment on the houses of the Albanians which were situated in the Azbakeya; but, on hearing of the flight of their chiefs, they evacuated the citadel.

Muhammad Ali Pasha, on gaining possession of the Cairo citadel, proclaimed Mahommed Khosrev Pasha governor of Egypt. For one day and a half Khosrev enjoyed the title; then the friends of the late Tahir Pasha succeeded in killing him. Cairo immediately descended into violent chaos at the hands of the triumphant Albanians, who ransacked and looted the houses of the Mamluk chiefs, whose harems were met with no mercy at their hands.

The Albanians then invited Hurshid Ahmed Pasha to assume the reins of government, and he without delay proceeded from Alexandria to Cairo.

In the meantime, the forces of the partisans of al-Bardisi were ravaging the countryside a few miles south of the capital and intercepting the river borne corn supplies. Soon thereafter, they advanced to the north of Cairo and successively took Bilbeis and Kalyub, plundering both, destroying the crops, and slaughtering the livestock.

Cairo was in a state of tumult, suffering severely from a scarcity of grain, as well as from the heavy exactions of the pasha to meet the demands of his troops, whose numbers had been augmented by a Turkish detachment. The shops were closed, and the unfortunate people assembled in great crowds, crying Y Latif! Y Latif! (O Gracious ).