Northern Morocco was part of ancient Mauretania, annexed by Rome in 42 A.D. The Vandals invaded in 429 and were overthrown in 533. In 682 the Arabs began their conquest, and the native Berbers were converted to Islam. The Moors, as the Muslim Arab-Berbers were known, invaded Spain from Morocco in 711.

Morocco gradually became a powerful center of the Muslim world. By the 11th century the ruling Moorish dynasty in Morocco controlled an empire extending from Spain to Libya. The Moors were driven from Spain in the 15th century, and a few Spanish and Portuguese settlements were made in Morocco. During the next four centuries Morocco successfully discouraged European settlements and resisted the Turks.

In the 19th century European powers began to take an active interest in North Africa. Morocco was defeated in a battle with Spain in 1859. France, already established in Algeria, invaded and occupied northern Morocco in 1860. Both Spain and France managed to establish themselves in the country, despite British and German disapproval.

In 1912 Morocco was divided into French and Spanish protectorates. It remained divided until 1956, when France and Spain recognized its independence and it was admitted to the United Nations. Friction with Spain continued over Spanish enclaves, and in 1969 Ifni, the largest one, was returned to Morocco.

In 1976 Morocco annexed the northern part of Spanish Sahara and Mauritania took the southern part. The takeover was fiercely resisted by the Polisario Front, a guerrilla organization wanting independence for the region. Mauritania relinquished its claim in 1979. Morocco then annexed the Mauritanian region. A cease-fire between Morocco and the Polisario Front was declared in 1991. The cease-fire called for a United Nations-supervised referendum to determine the future of the region, but the referendum was repeatedly postponed.

In 1999 King Hassan died. His son Sidi Mohammed then became king and was known as King Mohammed VI.