The region has experienced waves of invaders included Phoenicians, Carthaginians, Romans, Vandals, and Byzantines. In 702 the Berbers finally submitted to the armies of Islam and adopted Islam. For a millennia a series of Berber dynasties developed -- the Idrisid (from 788), Umayyad (from 926), Almoravids (from 1056), Almohads (from 1174), Marinid (from 1296), Wattasid (from 1465), Saadi (from 1554), and the Alawi (from 1666).
By the mid 1800s, at a time when the influence of Ottoman Empire was in decline, Europe was taking a great interest in Morocco. Algeciras Conference (1906) formalized France's special interest in the region (opposed by Germany). Treaty of Fez (1912) made Morocco a French protectorate, and Spain gained authority over Ifni (to the south) and Tétouan to the north.
In the 1920s the Rif Berbers of Morocco, under the leadership of Muhammad Abd el-Krim, rebelled against French and Spanish authority. The short lived Rif republic was crushed by a joint French/Spanish task force in 1926.
In 1953 France deposed the nationalist leader and sultan Mohammed V ibn Yusuf. Both nationalist and religious groups called for his return -- France capitulated, and Mohammed V returned in 1955. On 2 March 1956 French Morocco gained independence. Spanish Morocco, except for the two enclaves of Ceuta and Melilla, gained independence in April 1956.
Mohammed V was succeeded by his son, Hasan II ibn Mohammed, on his death in 1961. Morocco became a constitutional monarchy in 1977.
When Spain withdrew from Spanish Sahara in 1976, Morocco claimed sovereignty in the north. When Muritania withdrew in 1979, Morocco occupied the whole region.
When Hassan II died in 1999 he was succeeded by his son Mohammed VI ibn al-Hassan.