In the winter of AD 639, Amr ibn al As leading an Arab army coming from Syria entered Egypt . The Arabian Peninsula, Iraq and Syria were already under Muslim control, and the Khalif Omar had turned his armies against the two great hostile empires on his flanks- Persia in the east and Byzantium in the west.
In AD 640, Amr advanced not towards the capital Alexandria, but towards a more strategic goal, the fortress of Babylon, about 12km south of the point where the Nile divides to form the Delta. He defeated the Byzantine forces at Heliopolis then he encircled Babylon which was captured in April 641. Alexandria was Amr's next goal and by September 642 it was his by a treaty. The Arabs were welcomed by the Copts, who were reconciled to the Arabs who had rid them of Greek Melkites and allowed them to elect their own Patriarch.
On the orders of the Khalif Omar, a town was built beside the fortress of Babylon called Fustat. It was from Fustat, instead of Alexandria, that Egypt was administrated as a province of the Khalifate, first the Khalifs in Medina, then the Ummayyads in Damascus followed by the Abbasids in Baghdad.
From the conquest 642 A.D. until 868, Egypt was a province ruled either from Medina, Damascus or Baghdad, but from that time, 868, Egypt gained a sort of an autonomy when two dynasties the Tulunids followed by the Ikhshids ruled Egypt as a separate country until the Fatimids.
The Fatimids (969-1171) were the only Shietes who ever ruled Egypt. They were called as such since they claimed descent from Fatimah (the daughter of the Prophet Mohammed) and Ali the fourth Khalif. During the Fatimids' Period, the Crusaders came to in the Middle East and started occupying a great part of the Arab lands. The two ruling dynasties that followed the Fatimids as rulers of Egypt were the Ayyubids and the Mamluks. They were the rulers who carried the responsibility of fighting the Crusaders.
The Mamluks were defeated by the Ottomans (1516-17) and Egypt returned back to being a province and yielded to the Ottomans like the rest of the Empire that was ruled from Istanbul, until the French occupation (1798-1801), followed by Mohammed Ali, who started a dynasty that ruled Egypt till 1952, when the last member of his family was exiled out of the country by the revolution of the 23rd of July.