Morocco's recorded history begins with the Phoenicians establishing trading posts along the Atlantic and Mediterranean coasts around 1200 BCE. Carthage later controlled these settlements until Rome defeated Carthage in 146 BCE. The Romans annexed the region in 40 CE, creating the province of Mauretania Tingitana with its capital at Volubilis near present-day Meknes. Roman control extended south to the Oum Er-Rbia River but never penetrated the Atlas Mountains or Sahara Desert. Volubilis reached approximately 20,000 inhabitants by the second century CE, producing olive oil and grain for export to Rome. The Romans abandoned the province in 285 CE as the empire retrenched.
Berber kingdoms filled the vacuum left by Rome. The indigenous Berber population, speaking Tamazight languages, had occupied the region for at least three millennia before the Phoenicians arrived. No unified Berber state emerged during the post-Roman period. Christianity spread among some coastal Berber communities between the third and seventh centuries, but most Berbers practiced indigenous religions centered on local shrines and seasonal agricultural cycles.
Arab armies first entered Morocco in 681 CE under Uqba ibn Nafi, reaching the Atlantic coast before retreating. A second wave arrived in 705 CE led by Musa ibn Nusayr, who spent several years subduing Berber resistance. The Arabs introduced Islam, which spread rapidly despite initial armed opposition. By 710 CE, Arab commanders controlled the major cities and coastal plains. In 711 CE, Tariq ibn Ziyad, a Berber commander serving the Arab governor of North Africa, crossed the Strait of Gibraltar with approximately 7,000 troops, beginning the Muslim conquest of Iberia that would shape Moroccan history for eight centuries.
The first independent Moroccan dynasty arose when Idris ibn Abdallah, a descendant of Muhammad fleeing persecution in Arabia, reached Morocco in 788 CE. Berber tribes near Volubilis accepted him as imam. Idris I founded a state based in the region that would become Fes. Rival agents poisoned him in 791 CE. His son Idris II, born posthumously, took power in 803 CE and founded the city of Fes in 808 CE on the Sebou River. Idris II made Fes his capital and the city grew rapidly as Arab refugees from Cordoba arrived in 817-818 CE and refugees from Kairouan arrived in 824 CE. These migrations brought urban expertise, Islamic scholarship, and architectural traditions. The Kairaouine Mosque was founded in 859 CE by Fatima al-Fihri, a wealthy refugee from Kairouan, and became a center of Islamic learning. The Idrisid dynasty fragmented after Idris II's death in 828 CE, splitting into competing principalities controlled by his descendants.
The Almoravid dynasty emerged from the Sahara Desert in the 1040s. Abdullah ibn Yasin, an Islamic scholar, organized Sanhaja Berber tribes in present-day Mauritania into a religious-military movement. These desert warriors practiced a strict interpretation of Maliki jurisprudence. Abu Bakr ibn Umar led Almoravid forces north, capturing Sijilmasa in 1054 CE and Aghmat near present-day Marrakech in 1058 CE. Yusuf ibn Tashfin assumed military command and founded Marrakech in 1062 CE as a military encampment that became the capital. The Almoravids controlled Morocco by 1069 CE. When the Muslim taifa kingdoms in Iberia faced pressure from Christian forces after the fall of Toledo in 1085 CE, they requested Almoravid intervention. Yusuf ibn Tashfin crossed to Iberia and defeated Alfonso VI of Castile at the Battle of Sagrajas in 1086 CE. The Almoravids annexed the taifa kingdoms between 1090 and 1094 CE, creating an empire stretching from Senegal to Zaragoza. Yusuf ibn Tashfin died in 1106 CE at approximately 100 years old.
The Almohad movement began in the Anti-Atlas Mountains around 1120 CE. Ibn Tumart, a Berber scholar who had studied in Baghdad and Alexandria, declared himself the Mahdi and preached Islamic reform, rejecting Maliki legal interpretations and emphasizing direct return to Quran and hadith. His follower Abd al-Mumin organized Masmuda Berber tribes and launched military campaigns against the Almoravids. Abd al-Mumin captured Marrakech in 1147 CE after a nine-month siege, ending Almoravid rule. The Almohads controlled Morocco, western Algeria, Tunisia, and Muslim Iberia by 1160 CE. Abd al-Mumin died in 1163 CE. His grandson Yaqub al-Mansur ruled from 1184 to 1199 CE, defeating Alfonso VIII of Castile at Alarcos in 1195 CE. Yaqub al-Mansur built the Koutoubia Mosque in Marrakech, completed in 1158 CE with a minaret reaching 77 meters. He began construction of the Hassan Tower in Rabat in 1195 CE, intending a minaret of similar height, but the project remained incomplete at his death. The Almohads suffered decisive defeat at the Battle of Las Navas de Tolosa in 1212 CE against combined Christian forces. This loss shattered Almohad authority in Iberia and weakened control over North Africa.
The Marinid dynasty arose from Zenata Berber tribes in eastern Morocco. The Marinids captured Fes in 1248 CE and made it their capital. Abu Yusuf Yaqub ruled from 1258 to 1286 CE and expanded Marinid territory across Morocco. The Marinids intervened repeatedly in Iberia, crossing the Strait of Gibraltar to support the Emirate of Granada, the last Muslim state on the peninsula. Abu al-Hasan Ali ruled from 1331 to 1348 CE and briefly controlled western Algeria and Tunisia, but revolts and defeats forced retreat to Morocco. The Marinids patronized religious architecture, building numerous madrasas in Fes including the Bou Inania Madrasa completed in 1357 CE. Portuguese forces captured Ceuta in 1415 CE, beginning European territorial expansion in Morocco. The Marinid dynasty declined through the fifteenth century, retaining nominal authority while real power fragmented among regional rulers and Sufi zawiyas.
The Saadian dynasty emerged from the Draa Valley in southern Morocco. The Saadians claimed descent from Muhammad and built support by organizing resistance to Portuguese coastal expansion. Muhammad al-Shaykh captured Marrakech in 1524 CE and made it the capital. His son Abdallah al-Ghalib ruled from 1557 to 1574 CE. Ahmad al-Mansur assumed power in 1578 CE after the Battle of Ksar el-Kebir on August 4, 1578, where Moroccan forces defeated a Portuguese invasion led by King Sebastian I. Sebastian and approximately 8,000 Portuguese soldiers died in the battle. Ahmad al-Mansur ransomed thousands of Portuguese prisoners, generating enormous wealth that earned him the epithet "al-Mansur" meaning "the victorious" and "al-Dhahabi" meaning "the golden." He used this wealth to reorganize the army, importing firearms and artillery, and to construct the El Badi Palace in Marrakech, begun in 1578 CE using materials including Italian marble and Irish granite. In 1591 CE, Ahmad al-Mansur sent an army of approximately 4,000 soldiers equipped with muskets across the Sahara Desert under Judar Pasha to invade the Songhai Empire centered on Timbuktu and Gao. The Moroccan force defeated Songhai armies and captured the cities, establishing a military occupation that controlled the trans-Saharan gold trade. Ahmad al-Mansur died in 1603 CE. His sons fought a civil war that fragmented Saadian authority.
The Alaouite dynasty, which continues to rule Morocco, originated from Tafilalt in southeastern Morocco near the Sahara Desert. The Alaouites claimed descent from Muhammad through his grandson Hassan. Moulay Rashid unified Morocco between 1664 and 1672 CE, capturing Marrakech in 1668 CE and Fes in 1666 CE. His brother Moulay Ismail ruled from 1672 to 1727 CE, the longest reign in Moroccan history. Moulay Ismail created a standing army of enslaved Black Africans reportedly numbering 150,000 soldiers by 1700 CE, drawing on populations acquired through trans-Saharan trade networks and raids. He fortified Meknes, building massive walls, gates, and palaces that made it his capital. Moulay Ismail recaptured several coastal cities from European powers, including Mehdia from the Spanish in 1681 CE, Tangier from the English in 1684 CE, and Larache from the Spanish in 1689 CE. He maintained diplomatic relations with Louis XIV of France and attempted unsuccessfully to marry a French princess. Moulay Ismail died in 1727 CE. His death triggered a succession crisis that produced civil war lasting until 1757 CE.
Mohammed III ruled from 1757 to 1790 CE and restored stability. He founded Essaouira in 1760 CE as a fortified port designed by French architect Theodore Cornut, creating a base for international trade. Mohammed III was the first head of state to recognize American independence, issuing a declaration allowing American ships to use Moroccan ports in 1777 CE. The Moroccan-American Treaty of Friendship signed in 1786 CE remains the longest unbroken treaty relationship in United States history.
European pressure intensified during the nineteenth century. France occupied Algeria in 1830 CE, establishing a colonial presence directly on Morocco's eastern border. Spain held Ceuta and Melilla and sought expanded influence. Britain maintained commercial interests and viewed Morocco strategically regarding Gibraltar. Sultan Abderrahmane ruled from 1822 to 1859 CE and supported Algerian resistance leader Abd al-Qadir against French expansion, leading to French bombardment of Tangier and Essaouira in 1844 CE and Moroccan defeat at the Battle of Isly on August 14, 1844. Spain declared war in 1859 CE after incidents near Ceuta, defeating Moroccan forces and occupying Tetouan until Morocco paid a large indemnity.
Hassan I ruled from 1873 to 1894 CE and attempted to modernize the military and administration while preserving independence. He purchased modern weapons from European manufacturers and hired European military advisors. Hassan I died suddenly in 1894 CE during a military expedition. His son Abdelaziz became sultan at age fourteen. The regency period saw weakening central control. European powers competed for influence through loans and concessions. France expanded from Algeria into eastern Morocco. The Conference of Algeciras convened in Spain in 1906 CE with representatives from thirteen nations. The resulting Act of Algeciras signed on April 7, 1906 affirmed Moroccan independence but granted France and Spain control over police forces in Moroccan ports and established international oversight of Moroccan finances, effectively beginning the partition of sovereignty.
Abdelaziz's brother Abdelhafid overthrew him in 1908 CE with support from religious leaders and tribal groups opposing European influence. French forces advanced from Algeria and occupied Oujda in 1907 CE. French troops occupied Casablanca in August 1907 CE after riots killed nine European workers at the port. Abdelhafid faced rebellion and French military pressure. On March 30, 1912, Abdelhafid signed the Treaty of Fes, establishing a French protectorate over most of Morocco. Spain received a protectorate over northern Morocco along the Mediterranean coast and the Rif Mountains through agreements with France. Tangier became an international zone in 1923 CE administered by multiple European powers.
Hubert Lyautey served as French Resident-General from 1912 to 1925 CE. Lyautey preserved the sultanate as nominal authority while French officials controlled actual governance. He built new European quarters beside existing medinas rather than demolishing them. Lyautey created modern infrastructure including railways connecting Casablanca to Marrakech, Fes, and Oujda, and constructed the port of Casablanca with modern facilities. French colonists acquired agricultural land in the fertile plains, especially around Meknes and the Gharb region. The French administration introduced cash crops including citrus fruits and vegetables for export to France. Phosphate mining began at Khouribga in 1921 CE, developing into a major industry. Morocco held the world's largest known phosphate reserves, accounting for approximately seventy-five percent of global reserves by the 1950s.
Berber tribes in the Rif Mountains rebelled against Spanish rule in 1921 CE. Abd el-Krim al-Khattabi led the rebellion, establishing the Republic of the Rif in 1923 CE with its capital at Ajdir. Rif forces defeated a Spanish army at the Battle of Annual on July 22, 1921, killing approximately 8,000 Spanish soldiers. The rebellion expanded into French Morocco in 1925 CE. France and Spain deployed combined forces exceeding 250,000 soldiers. French forces used aircraft to bomb Rif positions. Abd el-Krim surrendered on May 26, 1926, ending the rebellion. France exiled him to Reunion Island.
Moroccan nationalism grew during the 1930s and 1940s. The Istiqlal Party formed in 1944 CE demanding independence. Sultan Mohammed V, who had assumed the throne in 1927 CE, increasingly aligned with nationalist demands. During World War II, American forces landed at Casablanca on November 8, 1942 as part of Operation Torch. President Franklin Roosevelt and Prime Minister Winston Churchill met at the Casablanca Conference in January 1943 CE, where Roosevelt privately encouraged Mohammed V to seek independence. French authorities arrested Mohammed V on August 20, 1953 and exiled him to Madagascar, replacing him with his uncle Mohammed Ben Aarafa. The arrest triggered widespread protests, riots, and an armed resistance movement. France faced a deteriorating security situation and the collapse of French control in neighboring Tunisia and Algeria. France negotiated Mohammed V's return. He arrived in Rabat on November 16, 1955. On March 2, 1956, France recognized Moroccan independence. Spain relinquished its northern protectorate on April 7, 1956. Tangier's international status ended and the city joined independent Morocco on October 29, 1956. Spain retained Ceuta and Melilla, which it still controls.
Mohammed V ruled independent Morocco until his death on February 26, 1961. His son Hassan II succeeded him. Hassan II faced two attempted military coups, the first on July 10, 1971 at his birthday celebration in Skhirat when military cadets attacked, killing approximately one hundred guests but failing to kill the king, and the second on August 16, 1972 when air force pilots attacked the king's Boeing 727 over Tetouan, damaging the aircraft but failing to shoot it down. Hassan II pursued territorial claims in the Western Sahara, a sparsely populated region south of Morocco controlled by Spain. Spain announced withdrawal from Western Sahara in 1975 CE. Hassan II organized the Green March on November 6, 1975, when approximately 350,000 Moroccan civilians marched into Western Sahara carrying Moroccan flags and Qurans. Morocco annexed the northern two-thirds of Western Sahara. The Polisario Front, supported by Algeria, fought for independence. A ceasefire began in 1991 CE. Morocco controls approximately eighty percent of Western Sahara behind a sand berm fortification stretching approximately 2,700 kilometers. The territorial status remains disputed.
Hassan II ruled until his death on July 23, 1999. His son Mohammed VI became king on July 30, 1999. Mohammed VI implemented political and social reforms including a new family code in 2004 CE that raised the minimum marriage age for women from fifteen to eighteen, gave women equal rights in divorce, and eliminated requirements for women to have male guardians. Morocco's population reached approximately 37 million by 2023. The constitutional monarchy maintains the king as head of state with executive authority while an elected parliament exercises legislative functions within limits defined by the constitution.
- Jamil M. Abun-Nasr, "A History of the Maghrib in the Islamic Period" (Cambridge University Press, 1987)
- Susan Gilson Miller, "A History of Modern Morocco" (Cambridge University Press, 2013)
- Daniel Rivet, "Histoire du Maroc: De Moulay Idrîs à Mohammed VI" (Fayard, 2012)