In the 19th century, the Albanian wālī Muhammad Ali established a dynasty that ruled over Egypt and Sudan until the middle of the 20th century. After a brief French invasion led by Napoleon Bonaparte and the Ottomans and Mameluks competing for power there, he managed collectively with his Albanian troops to become the Ottoman viceroy in Egypt. As he revolutionised the military and economic spheres of Egypt, his empire attracted Albanian people contributing to the emergence of the Albanian diaspora in Egypt initially formed by Albanian soldiers and mercenaries.