In theory, the Ottomans ruled Egypt from 1517 until 1882, although throughout the nineteenth century, Ottoman rule was extremely weak. Local rulers had far more influence over developments in Egypt than the rulers in Istanbul. When Napoleon tried to conquer Egypt during his tireless attempt to expand France into a mega-empire at the turn of the nineteenth century, Muhammed Ali defeated the French and the Ottomans, and gained control of Egypt in 1805. Egypt technically remained part of the Ottoman Empire, but as viceroy, Ali wielded almost exclusive control. During the next 30 years, he began the industrialization of Egypt and directed the expansion of agriculture toward cotton production, which was then exported to the textile factories of Britain for substantial profit.
Ali's westernization attempts were temporarily halted by his successor, Abbas I, but were reinvigorated under subsequent rulers, who worked with the French to begin construction of the Suez Canal. The canal, when completed in 1869, connected the Mediterranean Sea to the Indian Ocean, eliminating the need to go around the Cape of Good Hope. Because Britain had a huge colony in India, the canal became more important to the British than to anyone else. As Egypt's finances went into a tailspin because of excessive government spending, Egypt started selling stock in its canal to raise money, stock that the British government eagerly gobbled up. By 1882, Britain not only controlled the Suez Canal, but had maneuvered its way into Egypt to such a degree that it declared it a British protectorate, which was essentially a colony except that Egyptians remained in political power.
Pushed out of Egypt, France focused on other parts of North Africa, particularly Nigeria. The Italians too, once unified as a country, became interested in North Africa. The race for control of Africa was on.