Moroccan genetics encompasses the genetic history of the people of Morocco, and the genetic influence of this ancestry on world populations. It has been heavily influenced by geography.

In prehistoric times, the Sahara desert to the south and the Mediterranean Sea to the north were important geographical barriers to influx from Sub-Saharan Africa and Europe. However, West Asia and North Africa form a single land mass at the Sinai. Neolithic West Asian populations would have also been attracted to a wet Sahara, arriving either through the Suez, the Bab el-Mandeb or the Mediterranean.

As a result of these geographic influences, the genetic profile of the Moroccan population is a complex mosaic of autochthonous Maghrebi lineages, as well as North African, European, West Asian and West African elements in variable degrees. Though Northwest Africa has experienced gene flow from the surrounding regions, it has also undergone long periods of genetic isolation in some parts. This has allowed distinctive genetic markers to evolve in some Maghrebi populations, especially in certain isolated Berber-speaking groups.

The population of Morocco is genetically heterogenous. This is mostly due to the Arab migrations to the Maghreb, a demographic process that heavily implied gene flow and remodeled the genetic structure of the Maghreb. The J-M267 chromosome pool is derived not only from significant early Neolithic Revolution era dispersions from Western Asia, but to a much greater extent from recent expansions of Arab tribes from the Arabian Peninsula, during which both southern Qahtanite and northern Adnanite Arabs added to the heterogenous ethnic melting pot.

Prehistory and antiquity The area of present-day Morocco has been thought to have been inhabited since Paleolithic times, sometime between 90,000 and 190,000 BC, but that is no longer the case after the discovery of a 300,000 years Homo sapiens, and instead, it is now suggested that it has been inhabited since primordial times by humans by the same evidence.Field Projects – Jebel Irhoud . Department of Human Evolution. Max Planck Institute for Evolutionary Anthropology During the Upper Paleolithic, the Maghreb was more fertile than it is today, resembling a savanna more than today's arid landscape. 22,000 years ago, the Aterian culture which showed similarities with Cro-Magnon cultures of Eurasia was succeeded by the Iberomaurusian culture, which shared similarities with Iberian cultures. Skeletal similarities have been observed between the Iberomaurusian Mechta-Afalou burials and European Cro-Magnon remains. The Iberomaurusian industry in Morocco was succeeded by the Capsian culture.

North Africa and Morocco were slowly drawn into the wider emerging Mediterranean world by the West Asian Semitic Phoenicians, who established trading colonies and settlements in the early Classical period. Mogador was a Phoenician colony as early as the early 6th century BC.Moscati, Sabatino (2001) The Phoenicians, Tauris,

Morocco later became part of a Phoenocian North African and Iberian empire headquartered in Carthage. The earliest known independent Moroccan state was the Berber kingdom of Mauretania under king Bocchus I. This kingdom in northern Morocco, not to be confused with the present state of Mauritania, dates at least to 110 BC.

The Roman Empire controlled this region from the 1st century BC, naming it Mauretania Tingitana. Christianity was introduced in the 2nd century AD and gained converts in the Roman towns, among slaves and some Berber farmers.

In the 5th century AD, as the Roman Empire declined, the region was invaded from the north first by the Germanic Vandals and then by the Visigoths. In the 6th century AD, northern Morocco was nominally part of the East Roman, or Byzantine Empire. Throughout this time, the Berber inhabitants in the high mountains of the interior of Morocco remained unsubdued.

History

Early Arab era In 670 AD, the first Arab conquest of the North African coastal plain took place under Uqba ibn Nafi, a general serving under the Umayyads of Damascus. The Umayyad Muslims brought their language, their system of government, and Islam to Morocco. Many of the Berbers slowly converted to Islam, mostly after Arab rule had receded. The first independent Berber 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 Rashidun Caliphate. After the outbreak of the Great Berber Revolt in 739, the Berbers formed other independent states such as the Miknasa of Sijilmasa and the Barghawata.

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.

Berber dynasties

From the 11th century onwards, a series of powerful Berber dynasties arose. Under the Almoravid dynasty and the Almohad dynasty dominated the Maghreb, much of present-day Spain and Portugal, and the western Mediterranean region. In the 13th and 14th centuries the Merinids held power in Morocco and strove to replicate the successes of the Almohads by military campaigns in Algeria and Iberia. They were followed by the Wattasids. In the 15th century, the Reconquista ended Muslim rule in central and southern Iberia and many Muslims and Jews fled to Morocco. Portuguese efforts to control the Atlantic coast in the 15th century did not greatly affect the interior of Morocco. 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."Allo Isichei, Elizabeth (1997). A history of African societies to 1870. Cambridge University Press. p. 264.

Arab dynasties In 1549, the region fell to successive Arab dynasties claiming descent from the Islamic prophet, Muhammad: first the Saadi dynasty who ruled from 1549 to 1659, and then the Alaouite dynasty, who remained in power since the 17th century.

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 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 lies pressing westward. The Alaouites succeeded in stabilizing 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."Morocco (Page 8 of 9)". Microsoft Encarta Online Encyclopedia 2009. 2009-11-01. 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 recognize 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.Roberts, Priscilla H. and Richard S. Roberts, Thomas Barclay (1728–1793): Consul in France, Diplomat in Barbary, Lehigh University Press, 2008, pp. 206–223 .

Arab influx There have been several waves of Arab migration to Morocco. The most significant wave was the migration of Banu Hilal, Banu Sulaym and Maqil in the 11th century. They moved to the region of present-day Morocco in the 12th century when the Almohad ruler Abd al-Mu'min transferred them there in large numbers and settled them in the Atlantic plains, in a region previously inhabited by the Barghawata tribal group. This region was largely destroyed and depopulated by the Almoravids, then depopulated again by the Almohads in 1149–1150 and 1197–1198, before replacing the depopulated area with Arab Bedouin migrants. The Almohads helped the Arab tribes to pass the barriers of Atlas mountains, and accelerated their expansion to Morocco to complete the nomadic Bedouin predominance over the lowlands of the Maghreb as far as the Atlantic coastal plains. The appearance of the Arabs added to the complexity of the ethnic population of Morocco and introduced a significant non-Berber element. They increasingly played an important role in the politics of the Almohad Empire. The Almohad ruler Abd al-Mu'min expected opposition from the Masmuda to whom he was a stranger, so he gained Arab support to secure the succession of his son. With the decline of the Almohad army, the Arab Bedouins became the most powerful force in the Moroccan plains, and no ruler could have held authority there without their support.

Under the Marinids, the Arabs grew in importance in Morocco. Due to the lack of Zenata supporters, they welcomed the support of Arab nomads who already began to penetrate into the country under the Almohads. The Zenata were heavily assimilated into Arab culture and the Marinid Makhzan (government) composed of both Arabs and Zenata. This led to the expansion of Arab tribes into Morocco where they settled in the plains, and many Berber groups were Arabized. Under the Marinids, Arabic became both the common and official language. This demographic process heavily implied gene flow and remodeled the genetic structure.

Genetic evidence A genetic study published in January 2012 stated that the indigenous North West African ancestry appears most closely related to populations outside of Africa but "divergence between Moroccan people and Near Eastern/Europeans likely precedes the Holocene (>12,000 ya) and The Paleolithic (>40.000BC)."

According to a 2000 article in European Journal of Human Genetics, Moroccans from North-Western Africa, although still with many differences, are genetically closer to Southern Europeans than to Sub-Saharan Africans of Bantu ethnicity.

There is a substantial contribution of Sub-Saharan African DNA in about a third of Moroccan people, with the most West Eurasian Berbers showing contributions of 1-10% Sub-Saharan African DNA on average. Non Berber populations showed substantially more Sub-Saharan African DNA contributions (up to 55%). When it comes to Sub-Saharan African contributions, differences among Berber populations were not significant. Coudray et al. (2009) and Hernández et al. (2015) showed an increased representation of Sub-Saharan African mtDNA haplogroups in Figuig Berbers (i.e., high prevalence of L-derived lineages).