In the 19th cent. the strategic importance and economic potential of Morocco excited the interest of the European powers. France, after beginning war with Algeria, defeated (1844) Sultan Abd ar-Rahman, who had aided the Algerians. Spain invaded in 1860. In 1880 the major European nations and the United States decided at the Madrid Conference to preserve the territorial integrity of Morocco and to maintain equal trade opportunities for all.

Political and commercial rivalries soon disrupted this cordial arrangement and brought on several international crises. France sought to gain Spanish and British support against the opposition of Germany. Thus, in 1904, France concluded a secret treaty with Spain to partition Morocco and secretly agreed with Great Britain (the Entente Cordiale) not to oppose British aims in Egypt in exchange for a free hand in Morocco. In 1905, after France had asked the sultan of Morocco for a protectorate, Germany moved quickly: Emperor William II visited Tangier and declared support for Morocco’s integrity. At German insistence the Algeciras Conference (Jan.–Mar., 1906) was called to consider the Moroccan question. The principles of the Madrid Conference were readopted and German investments were assured protection, but French and Spanish interests were given marked recognition by the decision to allow France to patrol the border with Algeria and to allow France and Spain to police Morocco.

Under the claim of effecting pacification, the French steadily annexed territory. In 1908 friction arose at Casablanca, under French occupation, when the German consul gave refuge to deserters from the French Foreign Legion. This dispute was settled by the Hague Tribunal. Shortly afterward in a coup Abd al-Aziz IV was unseated and his brother, Abd al-Hafid, installed on the throne. He had difficulty maintaining order and received help from France and Spain, especially in a revolt that broke out in 1911. In this situation the appearance of the German warship Panther at Agadir on July 1, 1911, was interpreted by the French as a threat of war and speeded a final adjustment of imperial rivalries.

On Nov. 4, 1911, Germany agreed to a French protectorate in Morocco in exchange for the cession of French territory in equatorial Africa. Finally, at Fès (Mar. 30, 1912), the sultan agreed to a French protectorate, and on Nov. 27 a Franco-Spanish agreement divided Morocco into four administrative zones—French Morocco, nine-tenths of the country, a protectorate with Rabat as capital; a Spanish protectorate, which included Spanish Morocco, with its capital at Tétouan; a Southern Protectorate of Morocco, administered as part of the Spanish Sahara; and the international zone of Tangier. The French protectorate was placed under the rule of General Lyautey, who remained in office until 1925.