Muhammed Ali was appointed as the Ottoman Viceroy of Egypt in 1805, by the Sublime Porte. He commissioned this mosque, which was built between 1830 and 1848, and is situated on a 12th century citadel built by Salah-el-din al Ayyubi, the Kurdish military leader who ruled over Egypt and who defeated Richard the Lionheart in the second Crusade.
In the early years of his rule, Muhammed Ali's power was contested by the Mamluks, the slave warrior caste of the Ottoman empire who had ruled Egypt since the mid-13th century, and whose army had been defeated by Napolean in 1798.
In 1811, he invited the Mamluk amirs to the citadel under the pretense of a banquet, and ambushed and massacred them as they arrived. Legend has it that one amir escaped the ambush, and jumped onto a horse, on which he leapt - most likely to his doom - over the citadel's walls.
As I know - from the school- he was chosen by the Egyptians not by Ottoman empires. We all love him he is the leader of modern Egypt.
However, on his way to the top, Muhammad Ali changed sides several times, sometimes supporting the Mamluks against the Ottomans, and sometimes the Ottomans against the Mamluks. Yet, he knew that if he wanted to rule Egypt, which he did, he would have to contend with the Mamluks who were still the feudal owners of the land. The land had remained the real source of power and wealth in Egypt