Under the Saadi Dynasty, the country repulsed Ottomanincursions and a Portuguese invasion at the battle of Ksar el Kebir in 1578. The reign of Ahmad al-Mansur brought new wealth and prestige to the Sultanate, and a large expedition to West Africa inflicted a crushing defeat on the Songhay Empirein 1591. However, managing the territories across the Sahara proved too difficult. After the death of al-Mansur, the country was divided among his sons.
In 1666, Morocco was reunited by the Alaouite Dynasty, who have been the ruling house of Morocco ever since. Morocco was facing aggression from Spain and the Ottoman Empire allies pressing westward. The Alaouites succeeded in stabilising their position, and while the kingdom was smaller than previous ones in the region, it remained quite wealthy. Against the opposition of local tribes Ismail Ibn Sharif (1672–1727) began to create a unified state.With his Jaysh d'Ahl al-Rif (the Riffian Army) he seized Tangier from the English in 1684 and drove the Spanish from Larache in 1689.
Morocco was the first nation to recognise the fledgling United States as an independent nation in 1777. In the beginning of the American Revolution, American merchant ships in the Atlantic Ocean were subject to attack by the Barbary pirates. On December 20 1777, Morocco's Sultan Mohammed III declared that American merchant ships would be under the protection of the sultanate and could thus enjoy safe passage. The Moroccan–American Treaty of Friendship, signed in 1786, stands as the U.S's oldest non-broken friendship treaty.
Death of Spanish general Margalloduring the Melilla War. Le Petit Journal, November 13 1893.
Main articles: French Morocco and Spanish Protectorate in Morocco
As Europe industrialised, North Africa was increasingly prized for its potential for colonisation. France showed a strong interest in Morocco as early as 1830, not only to protect the border of its Algerian territory, but also because of the strategic position of Morocco on two oceans. In 1860, a dispute over Spain's Ceuta enclave led Spain to declare war. Victorious Spain won a further enclave and an enlarged Ceuta in the settlement. In 1884, Spain created a protectorate in the coastal areas of Morocco.
In 1904, France and Spain carved out zones of influence in Morocco. Recognition by the United Kingdom of France's sphere of influence provoked a strong reaction from the German Empire; and a crisis loomed in 1905. The matter was resolved at the Algeciras Conference in 1906. The Agadir Crisis of 1911 increased tensions between European powers. The 1912 Treaty of Fezmade Morocco a protectorate of France, and triggered the 1912 Fez riots. Spain continued to operate its coastal protectorate. By the same treaty, Spain assumed the role of protecting power over the northern and southern Saharan zones.
Tens of thousands of colonists entered Morocco. Some bought up large amounts of the rich agricultural land, others organised the exploitation and modernisation of mines and harbours. Interest groups that formed among these elements continually pressured France to increase its control over Morocco a control which was also made necessary by the continuous wars among Moroccan tribes, part of which had taken sides with the French since the beginning of the conquest. Governor general, Marshall Hubert Lyautey, sincerely admired Moroccan culture and succeeded in imposing a joint Moroccan-French administration, while creating a modern school system. Several divisions of Moroccan soldiers (Goumiers or regular troops and officers) served in the French army in both World War I and World War II, and in the Spanish Nationalist Army in the Spanish Civil War and after ("Regulares"). The institution of slavery was abolished in 1925.
Tangier's population included 40,000 Muslims, 31,000 Europeans and 15,000 Jews.
Between 1921 and 1926, a Berber uprising in the Rif Mountains, led by Abd el-Krim, led to the establishment of the Republic of the Rif. The rebellion was eventually suppressed by French and Spanish troops.
In 1943, the Istiqlal Party (Independence Party) was founded to press for independence, with discreet US support. That party subsequently provided most of the leadership for the nationalist movement.
France's exile of Sultan Mohammed V in 1953 to Madagascar and his replacement by the unpopular Mohammed Ben Aarafa sparked active opposition to the French and Spanish protectorates. The most notable violence occurred in Oujda where Moroccans attacked French and other European residents in the streets. France allowed Mohammed V to return in 1955, and the negotiations that led to Moroccan independence began the following year. In March 1956 the French protectorate was ended and Morocco regained its independence from France as the "Kingdom of Morocco". A month later Spain ceded most of its protectorate in Northern Morocco to the new state but kept its two coastal enclaves (Ceuta and Melilla) on the Mediterranean coast. Sultan Mohammed became king in 1957.
The Mausoleum of Mohammed V in Rabat.
Upon the death of Mohammed V, Hassan II became King of Morocco on 3 March 1961. Morocco held its first general elections in 1963. However, Hassan declared a state of emergency and suspended parliament in 1965. In 1971, there was a failed attempt to depose the king and establish a republic. A truth commission set up in 2005 to investigate human rights abuses during his reign confirmed nearly 10,000 cases, ranging from death in detention to forced exile. Some 592 people were recorded killed during Hassan's rule according to the truth commission.
The Spanish enclave of Ifni in the south was returned to Morocco in 1969. The Polisario movement was formed in 1973, with the aim of establishing an independent state in the Spanish Sahara. On 6 November 1975 King Hassan asked for volunteers to cross into the Spanish Sahara. Some 350,000 civilians were reported as being involved in the "Green March". A month later, Spain agreed to leave the Spanish Sahara, soon to become Western Sahara, and to transfer it to joint Moroccan-Mauritanian control, despite the objections and threats of military intervention by Algeria. Moroccan forces occupied the territory.
Moroccan and Algerian troops soon clashed in Western Sahara. Morocco and Mauritania divided up Western Sahara. Fighting between the Moroccan military and Polisario forces continued for many years. The prolonged war was a considerable financial drain on Morocco. In 1983, Hassan cancelled planned elections amid political unrest and economic crisis. In 1984, Morocco left the Organisation of African Unity in protest at the SADR's admission to the body. Polisario claimed to have killed more than 5,000 Moroccan soldiers between 1982 and 1985.
Algerian authorities have estimated the number of Sahrawi refugees in Algeria to be 165,000. Diplomatic relations with Algeria were restored in 1988. In 1991, a UN-monitored ceasefire began in Western Sahara, but the territory's status remains undecided and ceasefire violations are reported. The following decade saw much wrangling over a proposed referendum on the future of the territory but the deadlock was not broken.
Political reforms in the 1990s resulted in the establishment of a bicameral legislature in 1997 and Morocco's first opposition-led government came to power in 1998.
Protestors in Casablanca demand that authorities honor their promises of political reform.
King Hassan II died in 1999 and was succeeded by his son, Mohammed VI. He is a cautious moderniser who has introduced some economic and social liberalisation.