The rulers of Algeria supported the French in their 1798 invasion of Egypt and supplied Napoleon’s army with wheat, on credit, throughout the subsequent Napoleonic Wars (1799-1815). Thereafter, however, the French refused to repay their debt to Algeria and relations between them soured. In 1830 the French army occupied Algiers and overthrew the Algerian ruler. France annexed Algiers and the fertile coastal region in 1834 and invited in French settlers to occupy the land. Beyond the coastal regions, however, the French met the formidable resistance of Arab and Berber Muslims, led by marabout (Muslim holy man) Abd al-Qadir. By the 1840s the French needed an army in excess of 100,000 men to maintain their occupation and to wage the ongoing war. Although Abd al-Qadir was captured in 1847, French conquest of Algeria was not completed until the 1870s.
In the early 19th century the rulers of Libya and Tunisia, acting independently of Ottoman control, bought firearms from Britain and used them to extend their control into the interior regions of the Sahara. Libya took control of the Fezzan region in 1811 and thereafter stepped up the trade in slaves from the Bornu region by Lake Chad. The kingdom of Morocco maintained its independence throughout the 19th century, despite clashes with Spain along the Spanish-controlled northern coast and with France on the Algerian border. At the same time the Moroccan sultans extended more effective control over the remoter Berber regions of the interior.