Prehistory and antiquity
The area of present-day Morocco has been inhabited since Paleolithic times, sometime between 190,000 and 90,000 BC. A recent publication may demonstrate an even earlier habitation period, as Homo sapiens fossils discovered in the late 2000s near the Atlantic coast in Jebel Irhoud were recently dated to roughly 315,000 years before present. During the Upper Paleolithic, the Maghreb was more fertile than it is today, resembling a savanna more than today's arid landscape. Twenty-two thousand years ago, the Aterian was succeeded by the Iberomaurusian culture, which shared similarities with Iberian cultures. Skeletal similarities have been suggested between the Iberomaurusian "Mechta-Afalou" burials and European Cro-Magnon remains. The Iberomaurusian was succeeded by the Beaker culture in Morocco.
Mitochondrial DNA studies have discovered a close link between Berbers and the Saami of Scandinavia. This supports theories that the Franco-Cantabrian refuge area of southwestern Europe was the source of late-glacial expansions of hunter-gatherers who repopulated northern Europe after the last ice age.
North Africa and Morocco were slowly drawn into the wider emerging Mediterranean world by the Phoenicians, who established trading colonies and settlements in the early Classical period. Substantial Phoenician settlements were at Chellah, Lixus and Mogador. Mogador was a Phoenician colony as early as the early 6th century BC.
Morocco later became a realm of the North African civilisation of ancient Carthage as part of its empire. The earliest known independent Moroccan state was the Berber kingdom of Mauretania under king Baga. This ancient kingdom (not to be confused with the present state of Mauritania) dates at least to around 225 BC.
Mauretania became a client kingdom of the Roman Empire in 33 BC. Emperor Claudius annexed Mauretania directly as a Roman province in 44 AD, under an imperial governor (either aprocurator Augusti, or a legatus Augusti pro praetore).
During the crisis of the 3rd century, parts of Mauretania were reconquered by Berber tribes. Direct Roman rule became confined to a few coastal cities, such as Septum (Ceuta) in Mauretania Tingitana and Cherchell in Mauretania Caesariensis, by the late 3rd century. The Roman Empire lost its remaining possessions in Mauretania after the area was devastated by the Vandals in AD 429. After this point, local Mauro-Roman kings assumed control (see Mauro-Roman kingdom). The Eastern Roman Empire re-established direct imperial rule of Septum and Tingi in the 560s.
Foundation and early Islamic era
The indigenous Berber tribes adopted Islam, but retained their customary laws. They also paid taxes and tribute to the new Muslim administration. The first independent Muslim state in the area of modern Morocco was the Kingdom of Nekor, an emirate in the Rif Mountains. It was founded by Salih I ibn Mansur in 710, as a client state to the Umayyad Caliphate. After the outbreak of the Berber Revolt in 739, the Berbers formed other independent states such as the Miknasa of Sijilmasa and the Barghawata.
According to medieval legend, Idris ibn Abdallah had fled to Morocco after the Abbasids' massacre of his tribe in Iraq. He convinced the Awraba Berber tribes to break their allegiance to the distant Abbasid caliphs in Baghdad and he founded the Idrisid dynasty in 788. The Idrisids established Fes as their capital and Morocco became a centre of Muslim learning and a major regional power. The Idrissids were ousted in 927 by the Fatimid Caliphate and their Miknasa allies. After Miknasa broke off relations with the Fatimids in 932, they were removed from power by the Maghrawa of Sijilmasa in 980.
Portuguese efforts to control the Atlantic sea trade in the 15th century did not greatly affect the interior of Morocco even though they managed to control some possessions on the Moroccan coast but not venturing further afield inland.
On another note and according to Elizabeth Allo Isichei, "In 1520, there was a famine in Morocco so terrible that for a long time other events were dated by it. It has been suggested that the population of Morocco fell from 5 to under 3 million between the early sixteenth and nineteenth centuries."
Under the Saadi dynasty, the country repulsed Ottoman incursions 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 Empire in 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 1631, 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. Portuguese abandoned Mazagão, their last territory in Morocco, in 1769. However, the Siege of Melilla against the Spanish ended in defeat in 1775.
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 20 December 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.
French and Spanish protectorates
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 Fez made 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.
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 Spanish lost more than 13,000 soldiers at Annual in July–August 1921. 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 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.
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.
Mohammed VI paid a controversial visit to the Western Sahara in 2002. Morocco unveiled an autonomy blueprint for Western Sahara to the United Nations in 2007. The Polisario rejected the plan and put forward its own proposal. Morocco and the Polisario Front held UN-sponsored talks in New York but failed to come to any agreement. In 2010, security forces stormed a protest camp in the Western Sahara, triggering violent demonstrations in the regional capital El Aaiún.
In 2002, Morocco and Spain agreed to a US-brokered resolution over the disputed island of Perejil. Spanish troops had taken the normally uninhabited island after Moroccan soldiers landed on it and set up tents and a flag. There were renewed tensions in 2005 as hundreds of African migrants tried to storm the borders of the Spanish enclaves of Melilla and Ceuta. Morocco deported hundreds of the illegal migrants. In 2006 the Spanish Premier Zapatero visited Spanish enclaves. He was the first Spanish leader in 25 years to make an official visit to the territories. The following year, Spanish King Juan Carlos I visited Ceuta and Melilla, further angering Morocco which demanded control of the enclaves.
During the 2011–12 Moroccan protests, thousands of people rallied in Rabat and other cities calling for political reform and a new constitution curbing the powers of the king. In July 2011, the King won a landslide victory in a referendum on a reformed constitution he had proposed to placate the Arab Spring protests. Despite the reforms made by Mohammed VI, demonstrators continued to call for deeper reforms. Hundreds took part in a trade union rally in Casablanca in May 2012. Participants accused the government of failing to deliver on reforms.