There were two major crises involving France and Germany over the control of Morocco prior to World War I. France's interest in Morocco steadily increased after it took over neighboring Algeria in 1830.
Having not unified until 1870, Germany came late to the imperial game and had to content itself with attempting to secure territories that had not already been taken by other European imperial powers, particularly Britain and France. By the turn of the century, Morocco was one of the few African nations that had not been taken over by European powers, and the Germans were therefore interested in it.
Although it purported to be neutral on the Moroccan issue, Britain had secretly agreed to French expansion into the area during negotiations resulting in the beginning of the Entente Cordial in 1904.
The Tangier Crisis was the first clash between France and Germany. In 1905 Kaiser Wilhelm II visited Tangier, where he proclaimed his support for an independent Morocco. This provocation irritated the French government and raised public anger toward Germany.
The Moroccan sultan of the Alawi dynasty, seeking to prolong his rule, announced his support for an international conference that he hoped would result in Morocco's maintaining its independence. In 1906 13 nations, including the United States, gathered at the Algeciras Conference in southern Spain.
The Spanish already had small holdings in northern Morocco around the city of Ceuta. The Spanish and French subsequently agreed to separate spheres of influence in Morocco. After protracted negotiations France was granted special status in Morocco, although it pledged to respect German interests.
Secretly, Britain, fearing Germany's growing naval strength, reiterated its support for the French in Morocco. Sultan Abd al-Hafid (r. 1908–13) objected, but France continued to expand its control over Morocco's finances.
A small crisis, the so-called Casablanca Affair, broke out in 1908 when the French captured three German deserters from the French foreign legion while they were in the custody of the German consul, in violation of conventional international law.
Germany protested, and the matter was referred to the Hague Tribunal. Under the following Franco-German accord, Germany briefly accepted the special position of France but gained some economic concessions.
In 1911 France moved troops deep into Morocco and took the major city of Meknes. A second major crisis erupted when the Germans reacted by deploying a gunboat, the Panther, off the coast of the port city of Agadir in southern Morocco.
The British government publicly stated its support for France and even threatened Germany with possible war. Subsequent negotiations resulted in Germany's gaining a small piece of territory in French Equatorial Africa (in the present-day Republic of the Congo) and France's keeping its favored position in Morocco, by far the more important of the two territories.
France established a full protectorate over Morocco in the Treaty of Fez in 1912. The sultan was forced to sign the French terms, and Marshal Louis Hubert Lyautey was appointed the first French resident general of Morocco. France retained control until it granted Moroccan independence in 1956. The French and German rivalry over Morocco added to the mounting tensions among European nations and was a contributing factor to the outbreak of World War I in 1914.