Northwest African Neolithic initiated by migrants from Iberia and Levant Luciana G. Simões 5 Torsten Günther 5 Rafael M. Martínez-Sánchez 2 Juan Carlos Vera-Rodríguez 0 Eneko Iriarte 8 Ricardo Rodríguez-Varela 1 3 Youssef Bokbot 6 Cristina Valdiosera cevaldiosera@ubu.es 4 8 Mattias Jakobsson Mattias.jakobsson@ebc.uu.se 5 7 Área de Prehistoria, Departamento de Historia, Geografía y Antropología, Centro de Investigación en Patrimonio Histórico , Cultural y Natural, Facultad de Humanidades , Universidad de Huelva , Huelva , Spain Centre for Palaeogenetics , Stockholm , Sweden Departamento de Historia, Universidad de Córdoba , Cordoba , Spain Department of Archaeology and Classical Studies, Stockholm University , Stockholm , Sweden Department of History and Archaeology, La Trobe University , Melbourne, Victoria , Australia Human Evolution, Department of Organismal Biology and SciLifeLab, Uppsala University , Uppsala , Sweden Institut National des Sciences de l'Archéologie et du Patrimoine , Rabat , Morocco Palaeo-Research Institute, University of Johannesburg , Auckland Park , South Africa. ✉ Universidad de Burgos, Departamento de Historia , Geografía y Comunicaciones, Burgos , Spain 2023 618 550 561 3 5 2023 28 10 2022

In northwestern Africa, lifestyle transitioned fromforaging to food production around 7,400)years ago but what sparked that change remains unclear. Archaeological data support conficting views: (1) that migrant Eur opean Neolithic farmers brought the new way of life to North Afric1a33 or (2) that local hunter-gatherers adopted technological innovations4,5. The latter view is also supported by archaeogenet ic data6. Here we fll key chronological and archaeogenetic gaps for the Maghreb, from Epipalaeolithic to Middle Neolithic, by sequencing the genomes of nine individuals (to between 45.8- and 0.2-fold genome coverage). Notably, we trace 8,000)years of population continuity and isolation from the Upper Palaeolithic, via the Epipaleolithic, to some Maghrebi Neolithic farming groups. However,remains from the earliest Neolithic contexts showed mostly European Neolithic ancestry. We suggest that farming was introduced by European migrants and wasthen rapidly adopted by local groups. During the Middle Neolithic a new anc estry from the Levant appears in the Maghreb, coinciding with the arrival of pastoralism in the region, and all three ancestries blend together during the Late Neolithic. Our results show ancestry shifts in the Neolithization of northwestern Africa that probably mirrored a heterogeneous economic and cultural landscape, in a more multifaceted process than observed in other regions.

Check for updates
-

North Africa9s geographic location, centred betweenthe vast Saharan desert, the fertile Near East and Mediterranean Europe, has resulted in a complex human history in the area7,8. The fossil record suggests long-term hominid and human presence9, although continuity over the past 100,000)years cannot be deduced due to the fragmented nature of therecord.IntheLatePleistocene,15,000)yearsago,theremainsof foragers excavated in Morocco show a distinct genetic make-up intermediate between contemporary Levantine foragers and sub-Saharan African populations 10. Current-day North Africans are largely related toEurasian populations, which was probably caused by 8back-to- Africa9 migration7s.

Both archaeological records and archaeogenomic data show that Neolithic farmers (genetically distinct from European foragers) dispersed from the northern Levant and Anatolia to theMediterranean islands, Italian peninsula and Iberia 11318. Mediterranean coastal routes have long been recognized in the archaeological record as an important part of the Neolithic expansion in Europe. In the western Mediterranean, Impressed Ware technology4and further the Cardial Horizon4spread along the European mainland coast and islands to re ach the Iberian peninsula, where both phenomena are present at 7,55 0)calibrated years before the present)(calb)p) (refs.19,20).

Whereas some studies support a simultaneous appeara nce of the Neolithic in northwestern Africa (Eastern Rif, IfrOiudadane site) and Iberia around 7,550)cal)bp (ref.21), the earliest evidence for pottery, domestic cereals and husbandry is found in northern Morocco approximately two centuries later at Kaf Taht el-Ghar (KTG) around 7,350)cal)bp(refs.2,3,22,23). Although Early Neolithic material culture and the first domestic mammals and pulses suggest aconnection to Iberia133, the extent and legacy of these connections remainunclear.

However, the first genomic analysis of Early Neolihtic farmers from northwestern Africa (from the site Ifri n9Amr o9Msosua (IAM) in central Morocco) shows no traces of admixture with European Neolithic farmers. Instead, it shows long-term population continuity since the Upper Palaeolithic in the region 6. This result aligns with the hypothesis that the Neolithic transition in northwestern Africa was initiated by local Epipalaeolithic communities adopting technolo gical innovations4,5, such as those found at IAM: impressed Cardial-like ceramics, similar to those present throughout the western Mediterranean Neo lithic Europe, and domestic cereals (for example, a grain ofHordeum vulgaredatedaround7,050)calb)p)2.ThispatternimpliesaNeolithization process that contrasts markedly with that of Europe, where it has been established that agriculture was introduced by the west- and northward demic diffusion of Anatolian early farme1r1s,12. The local development, or acculturation, of the North African Neolithic isfurther supported by signs of increasingly sedentary Epipalaeolithic groups developing strategies for resource management, such as the exploitation of Contamination estimates were generally low for boththe nuclear wild plants and pottery 1,4,24326. Rapid climatic changes favoured mobile genome and mitochondria except for individual skh003, which showed herding27 and, whereas it has been hypothesized that cattle were inde- 10316% nuclear contamination (Table 1). To assess the relationship pendently domesticated in the Sahara 28, radiocarbon data suggest a of the ancient northwestern African individuals to other ancient and gradual introduction of pastoralism in the Sahara in a southwestwards present-day West Eurasian and African populations, we co-analysed direction 7,00036,000)cal)bp, possibly from the Near East29,30. our data with relevant ancient (Supplementary Data  2) and current-day

Whereas palaeogenomic studies on the European Medit erranean groups from Africa, the Middle East and Europe34. Neolithic transition are abundant15,31333, North Africa has been the focus of only a single study that generated human geneticdata from one Early and one Late Neolithic site6, leaving substantial gaps in the chronology Eight thousand years of population continuity of events. It is evident that the site of IAM showsa Neolithic lifestyle From the Upper Palaeolithic people of Taforalt (TAF) via the Epipalaeo and an absence of European Neolithic ancestry, but whether this was an lithic at OUB to the Early Neolithic at IAM, we observe the persistence independent development or the inspiration came from other groups in of the unique genetic make-up that existed in northwestern African northwestern Africa or across the Mediterranean Searemains unclear. inhabitants 15,000)years ago (Fig. 1c,d and Supplementary Fig. 5), Hence, the timeline and processes involved in the N eolithization of the and possibly even further back in time. The Epipalaeolithic individual region, the nature and dynamics of different econo mies in North Africa oub002, dating to 7,66037,506)cal)bp, is genetically very similar to and the role they may have played in the broader European Neolithic individuals from TAF ( 15,086314,046 )calb)p)35 and Early Neolithic indiremain understudied and controversial. viduals from IAM ( 7,31636,679 )calb)p; Fig. 1)6,36. The genome of Oub002

In this study we investigate a time series of humanremains from four demonstrates a marked population continuity in nort hwest Africa archaeological sites spanning the Epipalaeolithic to Middle Neolithic with no substantial gene flow across the Mediterranean Sea for at least in current-day Morocco: the Epipalaeolithic site of Ifri Ouberrid (OUB), 7,000)years across the Epipalaeolithic (Fig. 1c,d), linking the Maghrebi the Early Neolithic sites of IAM and KTG and the Middle Neolithic cem- genetic ancestry found in the Upper Palaeolithic to the Early Neolithic etery of Skhirat-Rouazi (SKH), co-analysed with previously published individuals at IAM. genetic data from that region6,10. By sequencing the genomes of nine The Maghrebi lineage shows outstandingly low genetic diversity6,10 individuals excavated from these four archaeologicalsites, we can (Fig. 2b and Supplementary Fig. 9) and long and frequent runs of demonstrate that the Neolithic transition in northwestern Africa was homozygosity (RoH) (Fig. 2a), probably as a consequence of long-lasting ignited by migration of Neolithic farmers from Medtierranean Europe. isolation. By investigation of the 45.8-fold genomeof oub002 we show

We generated genomic sequence data from nine ancient individu- that ancient northwestern Africans went through a severe populaals from modern-day Morocco (Table1 ), ranging in genome coverage tion bottleneck. Until some 70,000360,000)years agothe effective from 45.75- to 0.017-fold, including five individulas with more than population size ( Ne) changes of oub002 follow a pattern similar to that onefold coverage and three with more than ninefold. Chronologically of Eurasian populations with a relatively small effective population the data span more than 1,000)years, covering the Late Epipaleolithic size reached 50,000)years ago (Fig.2 c), which is consistent with the (n)=)1), Early Neolithic n()=)5) and Middle Neolithic n()=)3). Two Early Neo- Maghrebi lineage being related to the populations that migrated out lithic sites were studied4KTG ( n)=)4) and IAM4where we co-analysed of Africa. Interestingly, modern-day Eurasians and North Africans, as the newly generated genomic data of one individual and those previ- well as Neolithic Eurasians effective population size remained at around ously reported 6 (Fig. 1a,b). DNA libraries were generated from DNA 5,000 until about 30,000)years ago but the effectiev population size of extracts obtained from bones and teeth and subsequently shotgun the Maghrebi lineage continues to decrease and reached its lowest point sequenced on an Illumina platform. All libraries presented the degra- (Ne)j)1,400) between 50,000 and 27,000)years ago during the peak of dation patterns expected from ancient DNA, including short fragment the Last Glaciation. Remarkably similar patterns are observed for the sizes and cytosine deamination at read ends (Supple mentary Fig. 1). Mesolithic western hunter-gatherers (WHG) of Europe(represented

SKH

KEB d

Sub-Saharan

Africa by Loschbour in Fig. 2c), for which low diversity measures have been attributed to high levels of background relatedness and autozygosity due to small population size 37.

European farmers induce Neolithization

At the site of IAM, a multitude of artefacts representing the Neolithic package have been identified. However, it has been shown that the people living at IAM show autochthonous Maghrebi an cestry6 and were the descendants of earlier (Upper Palaeolithic and Epipaleolithic) northwestern African groups (Fig. 1c,d). These two observations sup port the view that the first stage of the Neolithic transition in Morocco was driven by local populations adopting technologi cal innovations based on contacts across the Mediterranean2.

The Early Neolithic site of KTG, located on the North African Mediterranean coast near the Gibraltar strait (Fig. 1a), predates and partly overlaps in time with IAM 2 (Table 1). At KTG a full Neolithic assemblage is found, including a diversity of cultivated cereals, domestic mammals and cardial ceramics38,39. In contrast to the people at IAM, those at KTG are genetically similar to European Early Ne olithic populations (Figs. 1c,d and 3a). Interestingly, all four KTG individuals show admixture (15.4327.4%) with local North African groups (Fig.  1d), consistent with significantly positive values for the f4 test of admixture (KTG, Each projected ancient individual is represented by a coloured symb ol. W. Eur., West European; hist., historical. d, Estimated ancestry proportions for relevant African, Middle Eastern and European (Eur.) modern- day and ancient individuals (assuming five ancestry components; additional results are presen ted in Supplementary Fig. 4). Pre-Neolithic and Neolithic northwest ern African populations/individuals are highlighted by the same symbols used in a and c.

Mediterranean EN; TAF, Mbuti) (Supplementary Data 7). Furthermore we identify a small proportion of WHG ancestry in KTG (Fig.  1d), consistent with the observation of Early Neolithic Europeans carrying WHG ancestry14,15,31,33,40. A population history model for the KTG people with 72)±)4.4% Anatolian Neolithic ancestry, 10)±).26% WHG ancestry and 18)±)3.3% Maghrebi ancestry is consistent with the data (qpAdm, P)=)0.193). Taken together, these results suggest aEuropean Neo lithic origin of KTG farmers whose ancestors dispersed from Anatolia throughout Europe, admixing with European hunter-ga therers on their path to southwestern Europe 33,40 before crossing the Mediterranean to North Africa. The presence of European hunter-ga therer ancestry excludes the possibility that Early Neolithic migrants exclusively followed North African Mediterranean shores from Anatolia or the Levant.

Iberian Early Neolithic (both as a whole and region ally) was found to be the best source population for the European a ncestry in KTG, followed by Sicily Stentinello Early Neolithic (Supplementary Data 9).

This is consistent with low levels of genetic differentiation in Cardial Ware-associated groups along the European shores of the Mediterranean Sea41, confirmed by direct radiocarbon dates showing tha t Impressed Ware farmers expanded rapidly across the western Mediterranean3,19,42.

It has been debated whether European farmers crosse d from Iberia to Morocco2,3 or whether earlier crossings of the Mediterranean ) b k ( s tn400,000 e m g e s e t go300,000 y z o m o h f tho200,000 g n e lf o um100,000 S 0

0 500,000 e z i s n o it lau 50,000 p o p e v it ffce 5,000 E b would have happened, through the Sicilian3Tunisian Strait followed by a Maghrebi route of expansion 4,43. Direct comparisons of Early Neolithic farmers from Sicily and Iberia as ancestors of KTG farmers provide stronger evidence for an Iberian Neolithic origin (Supplementary Data 9 and Supplementary Information 8), but we cannot exclude some con tribution from Sicilian farmers. Genetic data are consistent with the most parsimonious explanation for archaeological ev idence on the Neolithic transition in northwestern Africa: the crossing from southern Iberia by Iberian Neolithic farmers 2,23. The close geographical proximity between southern Iberia and the Tangitana Peninsula adds strength to this observation whereas the lack of reliable archaeological evidence of early domestic elements in relevant sites along the eastern Maghreb and Tunis, including sites with pottery and obsidian from Pantelleria Island, undermines the Sicily3Tunis crossing hypoth esis3. Interestingly, gene flow from North Africa was found only in Mediterranean European individuals much later, from around 4,500)years ago31,44.

Different individuals from KTG date to slightly different time periods.

We find a twofold larger proportion of Maghrebi anc estry in earlier KTG individuals (roughly 25%, ktg001 and ktg005, ap proximately 7,42937,267)cal)bp) than in later ones (about 13%, ktg004 and ktg006, around 7,24736,945)cal)bp) (Fig. 1d). This coincides with an increase in European Neolithic ancestry, shown by the signif icantly negative result for f4(KTG earlier, KTG later, Iberia Early Neolithic, Mb uti; z-score)=)25.01). Approximately one quarter of Maghrebi ancestry in early KTG suggests that they represent at least the second generation of interbreeding between the groups. We estimated t he time of admixture using two approaches based on ancestry covaria nce patterns and linkage disequilibrium decay, using Iberia or Sicily Early Neolithic and TAF as admixture sources. Both methods date the contact within the last six to 13)generations (Supplementary Information 8), suggesting that mixing between groups occurred for a few hundr ed years, which is consistent with analysis of pottery style that poin ts to the first contact at 7,50037,400)cal)bp (ref. 23).

Kaf Taht el-Ghar farmers had slightly lower genetic diversity levels and greater RoH than most Early Neolithic European populations (Fig. 2a,b and Supplementary Fig. 9). The Maghrebi ancestry c arried by KTG people shows markedly lower diversity and mo re extensive RoH, and is probably the cause of the reduction in overall diversity. iltano ilitch 0.025 anA eoN

0

Archaeological evidence suggests that Early Neolithic farming was If a European Neolithic (for example, from Iberia) additional source restricted to enclaves in westernmost Maghreb, poss ibly due to climatic population is added, the model is rejected. constraints to the south4,22. This could have limited the potential of Because this Neolithic Levantine ancestry has not been observed on these groups to recover from an initial founder effect. the European side of the Mediterranean during the N eolithic, it proba

Overall, the genetic patterns of local interaction between different bly represents an independent expansion of people f rom the Levant into groups in northwestern Africa are comparable to tho se found in Europe: North Africa. Migrations from the Levant to eastern Africa have been farmers assimilated local foragers9 ancestry in a unidirectional admix- identified for Neolithic pastoralist individuals around 4,000)years ago, ture process. Cases of hunter-gatherer communities adopting certain who are presumed descendants of unsampled northeast ern African elements of the Neolithic have been described in Eu rope 11,14,45. However, populations associated with the spread of Saharan p astoralism46. Both the northwestern Africa Neolithization process involved the notable in SKH and eastern African Neolithic pastoralists, Levantine ancestry is survival of genetically unadmixed local populations (represented by admixed with local ancestries (Fig. 1d, Supplementary Information 8 IAM), despite coexisting for at least 300)years with foreign farming and Supplementary Data 12). The arrival of this Lev antine ancestry communities (KTG), and still adopted several elemen ts of the Neolithic coincides with the appearance of a new ceramic tradition in northern ways of living from them. Whereas the archaeological findings in IAM Morocco, often characterized by cord-impressed motifs (8roulette9 or and KTG point to the exchange of ideas between groups and support wavy line), like the grave goods at Skhirat belonging to Ashakar Ware an acculturation process of foraging communities 1,4, our genetic data pottery 47,48. In parallel, cattle pastoralism was expanding in the current show that the exchange of genes was unidirectional. Sahara territory30,47 and Afro-Asiatic language groups spread through out the whole of North Africa22.

Our analyses show that the Levantine-associated component also Influx of Levantine ancestry remains in the Maghreb during the Late Neolithic in individuals from Another, distinct, ancestry was introduced to northwestern Africa dur- Kehf el Baroud (KEB) and in the Guanches of the Canary Islands (around ing the Middle Neolithic. All individuals from SKH show large propor - 1,000)cal)bp; Fig. 1c,d)6,49. Individuals from these sites are shifted tions of a genetic component maximized in individua ls from Neolithic towards ancient Levantine populations on the princi pal component and Chalcolithic Levant, Ptolemaic Egypt and modern -day Near Eastern analysis (PCA) space (Fig. 1c). This highlights the complex demographic populations (Fig.  1d). The ancestry in SKH can be modelled as a two-way processes that took place in northwestern Africa, i n contrast to the admixture between Levant Neolithic populations (rou ghly 76.4)±)4.0%) gradual increase in hunter-gatherer ancestry described in Middle and and local northwestern Africans (represented by TAF ; 23.6)±)4.0%). Late Neolithic Europe 32,33,40.

The Late Neolithic individuals from KEB can be modelled as a mix

of ancestries already present in northwestern Africa during the Early Neolithic and Middle Neolithic, suggesting that there were no waves of substantial migration into this region between t he Middle Neolithic and Late Neolithic (Supplementary Information 8 and Supplementary Data 13).

Conclusion

The complex population structure in modern-day nort hwestern Africa has been linked to various historical events, such as the Arab expansion7,8. However, our detailed chronology and high-resolution genomic data provide a new understanding of these prehistor ic processes in the Maghreb and unveil a rich and diversified genetic substrate with Neolithic origin. First, human populations in north western Africa show genetic continuity and isolation since the Upper Palaeolithic, from at least 15,000 to around 7,500)years ago, when this period of isolation was interrupted by the migration of European Early Neolithic groups introducing farming practices. Hence, despite a relatively small geographic distance between southern Iberia and northw estern Africa (the distance today is only 13)km across the Gibraltar straight), and the fact that both regions were populated by foragers for many millennia prior to the Neolithic, gene flow across the Medite rranean Sea was not established until the Early Neolithic. The newcomers brought new ways of life, farming practices, domestication and potte ry traditions that were subsequently adopted by local populations. Our results show that the Neolithization process in northwestern Afr ica was ignited by migrant Neolithic Europeans, but that local grou ps (at least the individuals analysed at IAM) adopted some of these practices without mixing with the newcomers. Two genetically distinct groups coexisted in close proximity in the region. Interestingly, cu ltural and technological knowledge appear to have been transferred mainl y from European Neolithic farmers to local groups (for example, at IAM) whereas genetic ancestry flowed only from local groups to the incoming farmers, such as the population of KTG. Furthermore, in the Middle Neolithic a new ancestry with an eastern origin is detected in northwestern Africa. This ancestry indicates new migrating groups, potentially associated with Sahara pastoralists, which admixed with local groups (Fig.  3c).

The various waves of migration and admixture into northwestern Africa during the Neolithic possibly resulted in a heterogeneous eco nomic and cultural landscape in that region4a mosaic of groups that included incoming farmers from Iberia, foragers adopting farming practices and eastern pastoralists admixing with lo cal people. Most of these groups showed reduced effective population size and lower diversity than the contemporary populations in Euro pe (Fig. 2), suggesting that population sizes remained modest throughout the Neolithic. These patterns were probably caused by periods of i solation, which may have contributed to the distinct genetic ancestry seen in the Maghreb today. A recent study from the Iron Age suggests that northwestern Africa remained home to a diverse set of groups thr oughout prehistory50, making this part of the world one of the most unique places to have been studied with the archaeogenomic toolkit.

Online content

Any methods, additional references, Nature Portfolio reporting summa ries, source data, extended data, supplementary inf ormation, acknowledgements, peer review information; details of author contributions and competing interests; and statements of data and code availability are available at https://doi.org/10.1038/s41586-023-06166-6 .

Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/. Detailed descriptions for each section can be found in Supplementary Information.

Archaeological sampling

The ancient human remains analysed in thisstudy derive from a scientific cooperation agreement between INSAP, La Trobe and U ppsala Univer sities. Complete bone and teeth elements were broug ht to the ancient DNA facility in Uppsala, Sweden for further cleanin g and sampling.

Radiocarbon dating

All individuals investigated were directly radiocarbon dated at the Tandem Laboratory, Uppsala, except for ktg001, who was dated at the Beta Analytic Carbon dating laboratory, and iam004, who9s date was obtained from ref. 6. Radiocarbon calibration for newly reported and relevant previously published dates was performed using Oxcal v.4.4 and the IntCal20 dataset41.

Ancient DNA retrieval

Human remains were sampled in dedicated clean-room laboratories at Uppsala University, Sweden after a series of str ingent procedures aimed at minimization of bone and tooth surface contamination. Thirty to sixty milligrams of bone powder or solid pieces of bone material were used for DNA extraction either following ref. 51, with adapta tions as described in ref. 15, or following ref. 52, with adaptations to the binding buffer, and an initial predigestion ste p with 1)ml of 0.5)M EDTA pH)8.0 for 30)min at 37)°C53. Sample digestion was performed overnight with 1)ml of 0.45)M EDTA pH)8.0 and 0.2)mg)ml31 proteinase)K. Double-stranded, blunt-end-repaired DNA libraries w ere built with ligated P5 and P7 adaptors 54. After assessment of DNA authenticity, quality and quantity (by estimation of endogenous DNA content, post mortem deamination patterns and fragment size distr ibution), the remaining DNA extract (for samples with over 1% pro portion of human DNA) was used to build four to six additional doubl e-stranded DNA libraries; for extracts with roughly 5% endogenous human content or more, 15320)µl of DNA extract was treated with uracil DNA glycosylase (UDG) for double-stranded library building 55. Libraries were PCR ampli fied using a unique 7)bp indexed primer54,56 in either four reactions of 25)µl or two of 50)µl, with the application of 12320)PCR cycles depending on previous qPCR quantification cycle indication. Two extraction negative controls, two library negative controls and one PCR negative control were included per sample batch. PCR reactio ns were pooled and purified with AMPure XP beads (Agencourt, Beckm an Coulter). Library quality was checked by electrophoresis on T apestation (Agilent High Sensitivity D1000 ScreenTape, Agilent) and DNA concentration was quantified using a Qubit dsDNA HS (High Sensitivity) Assay Kit (Invitrogen). Equimolar pools of amplified and purified libraries were sequenced on Illumina HiSeq)X at the SNP & SEQ Technology Platform in Uppsala. To reach higher coverage, between four and ten libraries were pooled equimolarly and sequenced to depletion.

Bioinformatics data processing and authentication

Data were demultiplexed according to the indexed pr imer sequence and adaptors were trimmed with either MergeReadsFastQ_cc.py 57 or Adapter Removal v.2.1.7 (ref. 58). Forward and reverse paired-end reads were merged when an overlap of at least 11)bp was found. Mapping against the human reference genome build)37 (hs37d5) was done using Burrows3Wheeler aligner 0.7.13 (ref. 59). For each library we merged bam files resulting from all resequencing rounds using SAMtools merge v.1.5 (ref. 60). We then separately merged data from UDG-treated and untreated libraries for each individual and used data from the former for subsequent analysis, except for individuals ktg001 (fo r which only non-UDG data were generated) and iam004 (for which both treated and untreated data were merged and processed as non -UDG treated for downstream analysis). We used a modified version of FilterUniqSAMCons_cc.py 57 to ensure random choice of bases to collapse reads with identical start and end positions into a consensus, thereby removing PCR duplicates. Reads shorter than 35)bp and more than 10% mismatches to the human reference genome were filtered out.

Contamination, sex determination, uniparental markers and kinship analyses

Sample contamination estimates were obtained using three different methods based on the mitochondrial genome61, on the X)chromosome in males62 and on nuclear data63 (Supplementary Data 3). The ratio of coverage of X and Y)chromosomes relative to autosomes was used to determine the biological sex of each individual64. We generated mitochondrial consensus sequences using SAMtools)1.5 mpileup and vcfutils.pl 60,65. Base (BQ) and mapping quality (MAPQ) scores were set to MAPQ)>)30 and BQ)>)30, and only sites withtaleast threefold coverage were used. Haplogroups were assigned using Haplogrep 2.1.16 (ref. 66) and PhyloTree mtDNA tree Build)17 ( 18 )February 2016)67 (Supplementary Data 4). For Y)haplogroup inference we called SNPs from the International Society of Genetic Genealogy (http://isogg.org ; v.11.110, 21)April 2016)) from bam files using SAMtools mpileup with option -B. We extracted sites with mapping and base quality greater than 30. Insertions and deletions, and sites showing multiple alleles, were excluded (Supplementary Data 5).

We ran kinship analysis with READ 68 within each archaeological site (minimum of three individuals; Supplementary Fig. 2). When a pair of individuals with close kinship was found, such as f irst-degree relationships (parent3offspring or a full sibling), we excl uded the individual with fewer SNPs covered from the analyses. This resulted in the removal from the analysis of iam4 (same individual as iam5), keb8 (same individual as keb1), iam6 (first-degree relative to iam004)6 and TAF012 (first-degree relative to TAF011)10.

Population genomics analysis of pseudohaploid data

Data from over 300)ancient Eurasian, North African and Sub-Saharan African individuals, organized according to geograp hy and chronology (Supplementary Data 2), were downloaded, mapped and processed though the same pipeline as used for newly generate d data. The full ancient DNA dataset was merged with publicly access ible modern-day individuals sampled across the globe from the Simons Genome Diver sity Project (SGDP) dataset34 for a 2.2)million SNP panel64. Alleles were sampled from bam files by randomly drawing one read with MAPQ)>)30 and BQ)>)30 per SNP site for each ancient individual (using SAMtools v.1.5.0 mpileup with option -B), and that position was treated as (pseudo)haploid. For non-UDG-treated data (ktg001) or merged UDG and non-UDG data (iam004) we trimmed off 10)bp of sequence-ends to avoid integration of miscoding C-to-T and G-to-A substitutions. For the published partial UDG-treated data (UDG-half), 2)bp were trimmed off the sequence-ends. SNPs showing more than two alleles were excluded from the data, leaving 1,379,466)SNPs for analysis.

Principal component analysis was performed using sm artpca v.10210 (ref. 69). Principal components were calculated based on individuals from 18)Mediterranean Eurasian or North African modern-day popula tions from SGDP. Ancient individuals were projected onto the PCA space with options shrinkmode: YES and lsqproject: YES. A n unsupervised model-based clustering algorithm, implemented in AD MIXTURE v,1.3.0 (ref. 70), was performed for K)=)335 ( 30 )runs) on a fully pseudohaploidized, linkage disequilibrium-pruned dataset of modern-day and ancient individuals from Mediterranean Eurasian or North African populations, leaving 812,092)SNPs for analysis. The results were parsed, aligned and plotted with pong 71.

Popstats 72 was used to calculate f-statistics73, with Mbuti set as the outgroup (Supplementary Data 6 and 7). Outgroup- f3 statistics were computed with the option 3f3vanilla. Standard errors (SEs) were calculated with a weighted block jack-knife approach.

Admixture modelling was performed with qpAdm 74 using ADMIX

TOOLS v.5.0, through an adapted version of qpAdm_wr apper ( https:// github.com/pontussk/qpAdm_wrapper ) that cycles through all possible subsets of the list of source populations provided (selected based on pre vious results), to test one-, two-, three- and four-way admixture models.

SEs were computed with 5cM block jack-knife. We use d a set of 11)reference populations whose power to disentangle diver gent strains of ancestry present in Europe, North Africa and the Ne ar East has previously been described and that are differently related to the sources tested10,31,75.

Distantly related sources were explored and, where possible, also more proximate groups (geographically, chronologically o r according to standing archaeological evidence). We tried to find the most parsimonious models consistent with the data (P)>)0.05) by checking the lowest 61. Fu, Q. et al. A revised timescale for human evolution based on ancient mitochondrial genomes. Curr. Biol. 23, 5533559 (2013). possible number of ancestry sources necessary to ex plain the ancestry in 62. Rasmussen, M. et al. An Aboriginal Australian genome reveals separate human dispersals each test population (Supplementary Data 8313). The Admixture event into Asia. Science 334, 94398 (2011). in KTG was dated using ALDER76 and DATES77 (Supplementary Informa - 63. Jun, G. et al. Detecting and estimating contamination of human DNA samples in sequencing and array-based genotype data. Am. J. Hum. Genet. 91, 8393848 (2012). tion 8). We calculated conditional nucleotide diversity78 by estimation 64. Fu, Q. et al. The genetic history of ice age Europe. Nature 534, 2003205 (2016). of the average number of mismatches between two ind ividuals of the 65. Danecek, P. et al. The variant call format and VCFtools. Bioinformatics 27, 215632158 (2011). same population. SEs were estimated using a block j ack-knife approach 66. Weissensteiner, H. et al. HaploGrep 2: mitochondrial haplogroup classification in the era of high-throughput sequencing. Nucleic Acids Res. 44, W583W63 (2016). and a block size of 2,000)SNPs (Supplementary Fig. 9). 67. Van Oven, M. PhyloTree Build 17: growing the human mitochondrial DNA tree. Forensic Sci. Int. Genet. Suppl. Ser. 5, e3923e394 (2015).

Population genomics analysis of diploid data 68. Monroy Kuhn, J. M., Jakobsson, M. & Günther, T. Estimating genetic kin relationships in prehistoric populations. PLoS ONE 13, e0195491 (2018).

Diploid genotype calls for a panel of 49,791,572)SN Ps were performed for 69. Patterson, N., Price, A. L. & Reich, D. Population structure and eigenanalysis. PLoS Genet. northwestern African ancient individuals with at least ninefold genome 2, e190 (2006). coverage (oub002, ktg004 and skh001), as well as relevant, previously 70. Alexander, D. H., Novembre, J. & Lange, K. Fast model-based estimation of ancestry in unrelated individuals. Genome Res. 19, 165531664 (2009). published ancient individuals with sequenced high-c overage genomes. 71. Behr, A. A., Liu, K. Z., Liu-Fang, G., Nakka, P. & Ramachandran, S. Pong: fast analysis and Before genotype calling, base quality in read ends was reduced and indel visualization of latent clusters in population genetic data. Bioinformatics 32, 281732823 realignment conducted with GATK)3.5.0. Diploid genotypes were called (2016). 72. Skoglund, P. et al. Genetic evidence for two founding populations of the Americas. Nature using dbSNP v.142 as known SNPs, with GATK9s UnifiedGenotyper 79. We 525, 1043108 (2015). computed average sequencing depth (avg.DP) over all called positions 73. Patterson, N. et al. Ancient admixture in human history. Genetics 192, 106531093 (2012). for each individual and filtered for QUAL)>)30 anda depth span from five - 74. Haak, W. et al. Massive migration from the steppe was a source for Indo-European languages in Europe. Nature 522, 2073211 (2015). fold to 3×)avg.DP)per individual, using BCFtools view. This dataset was 75. Harney, É. et al. Ancient DNA from Chalcolithic Israel reveals the role of population merged with data from modern-day individuals from the SGDP dataset. mixture in cultural transformation. Nat. Commun. 9, 3336 (2018).

Individual heterozygosity was calculated from the number of variable 76. Loh, P.-R. et al. Inferring admixture histories of human populations using linkage disequilibrium. Genetics 193, 123331254 (2013). positions divided by that of sequenced SNPs, using the 3het command 77. Narasimhan, V. M. et al. The formation of human populations in South and Central Asia. in PLINK 1.9 (ref. 80). We estimated the length and number of runs of Science 365, eaat7487 (2019). homozygosity after filtering with the command PLINK 3geno)0. MSMC81 78. Skoglund, P. et al. Genomic diversity and admixture differs for Stone-Age Scandinavian foragers and farmers. Science 344, 7473750 (2014). input files were generated from VCF files. Filters for MAPQ)>)30, mini- 79. DePristo, M. A. et al. A framework for variation discovery and genotyping using nextmum genotype quality of 50 and sequencing depth wer e used. Sites generation DNA sequencing data. Nat. Genet. 43, 4913498 (2011). not passing these filters were masked out per individual. MSMC)0.1.0 80. Purcell, S. et al. PLINK: a tool set for whole-genome association and population-based linkage analyses. Am. J. Hum. Genet. 81, 5593575 (2007). was then run for each individual. 81. Schiffels, S. & Durbin, R. Inferring human population size and separation history from multiple genome sequences. Nat. Genet. 46, 9193925 (2014).

Ethics and inclusion statement

The sampling for this study emerged from archaeology projects that involved local universities and researchers, including Y.B., whose involvement in research design included the selection of archaeological material for analyses as well as sampling s upervision. The local relevance of this research is tied to the region9s history, and it is locally relevant in regard to describing the human past in northwestern Africa. The study was undertaken with the highest standards of archaeogenomic research, and relevant research by local scholars was cited.

Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.

Data availability

The sequence data generated for this study are available from the European Nucleotide Archive under accession no. PRJEB59008.

Funding Open access funding provided by Uppsala University.

Competing interests The authors declare no competing interests.

Additional information Supplementary information The online version contains supplementary material available at https://doi.org/10.1038/s41586-023-06166-6.

Correspondence and requests for materials should be addressed to Cristina Valdiosera or Mattias Jakobsson.

Peer review information Nature thanks the anonymous reviewers for their contribution to the peer review of this work.

Reprints and permissions information is available at http://www.nature.com/reprints.

Corresponding author(s): Mattias Jakobsson Last updated by author(s): 14/04/23 Reporting Summary Nature Portfolio wishes to improve the reproducibility of the work that we publish. This form provides structure for consistency and transparency in reporting. For further information on Nature Portfolio policies, see our Editorial Policies and the Editorial Policy Checklist. Statistics n/a Confirmed For all statistical analyses, confirm that the following items are present in the figure legend, table legend, main text, or Methods section.

The exact sample size (n) for each experimental group/condition, given as a discrete number and unit of measurement A statement on whether measurements were taken from distinct samples or whether the same sample was measured repeatedly The statistical test(s) used AND whether they are one- or two-sided Only common tests should be described solely by name; describe more complex techniques in the Methods section.

A description of all covariates tested A description of any assumptions or corrections, such as tests of normality and adjustment for multiple comparisons A full description of the statistical parameters including central tendency (e.g. means) or other basic estimates (e.g. regression coefficient) AND variation (e.g. standard deviation) or associated estimates of uncertainty (e.g. confidence intervals) For null hypothesis testing, the test statistic (e.g. F, t, r) with confidence intervals, effect sizes, degrees of freedom and P value noted Give P values as exact values whenever suitable.

For Bayesian analysis, information on the choice of priors and Markov chain Monte Carlo settings For hierarchical and complex designs, identification of the appropriate level for tests and full reporting of outcomes Estimates of effect sizes (e.g. Cohen's d, Pearson's r), indicating how they were calculated

Our web collection on statistics for biologists contains articles on many of the points above.

Software and code Policy information about availability of computer code

Data collection Data analysis

Sequence demultiplexing: MergeReadsFastQ_cc.py, Adapter Removal v2.1.7.

Simons Genome Diversity Project datasets (https://www.simonsfoundation.org/simons-genome-diversity-project/) available on UPPMAX. Comparative ancient individuals' genomic data downloaded from the European Nucleotide Archive (ENA), under the accession numbers provided in the references listed in Supplementary Data File 2.

A full description of all software and respective packages used for data analysis can be found in the Supplementary Information document and are publicly available. For genomic reads mapping: Burrows-Wheller Aligner (BWA, v. 0.7.13); genomic libraries merging: samtools v. 1.5. mtDNA contamination estimates: contamMix (1.0-10); X-chromosome contamination estimates: ANGSD v. 0.902; autosomal contamination estimates: verifyBamID v.1.1.2. Mt haplogroup assignement: Haplogrep v. 2.1.16 and PhyloTree mtDNA tree Build 17 (18 Feb 2016); Y chromosome haplogroup assignement: ISOGG (10, April 21, 2016) SNPs called using samtools v. 1.5. Pseudohaploid genomic dataset management (including LD pruning and datasets merging): PLINK v. 1.9. Kinship analysis: READ. PCA: smartpca v.10210 (EIGENSOFT package); model-based clustering analysis: ADMIXTURE v. 1.3.0 and PONG v. 1.5. f -statistics: python script POPSTATS (https://github.com/pontussk/ popstats); Admixture modelling: qpAdm (ADMIXTOOLS v. 5.0) via qpAdm_wrapper (https://github.com/pontussk/qpAdm_wrapper); Admixture graphs: ADMIXTOOLS2 findGraphs function. Admixture dating: ALDER v. 1.03 and DATES v. 753. Diploid genotype calling GATK v. 3.5.0. Diploid genomic dataset management (including SNP selection) Vcftools v. 0.1.16 and Plink v. 1.9. Runs of Homozygosity: Plink v. 1.9. Pairwise Sequentially Markovian Coalescent (PSMC) implemented on MSMC v. 0.1.0. Phenotypic variation analysis: ANGSD v. 0.933. Results visualization and plot generation: R v. 3.4.067, ggplot2. Radiocarbon dates calibration: Oxcal v4.4 and IntCal20.

For manuscripts utilizing custom algorithms or software that are central to the research but not yet described in published literature, software must be made available to editors and reviewers. We strongly encourage code deposition in a community repository (e.g. GitHub). See the Nature Portfolio guidelines for submitting code & software for further information. Policy information about availability of data All manuscripts must include a data availability statement. This statement should provide the following information, where applicable: - Accession codes, unique identifiers, or web links for publicly available datasets - A description of any restrictions on data availability - For clinical datasets or third party data, please ensure that the statement adheres to our policy Human reference genome build 37 (hs37d5) (https://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/reference/phase2_reference_assembly_sequence/) All the generated sequence data are available as bamfiles of aligned reads at the European Nucleotide Archive (ENA) under the accession number PRJEB59008. Human research participants Policy information about studies involving human research participants and Sex and Gender in Research.

Reporting on sex and gender Population characteristics Recruitment Note that full information on the approval of the study protocol must also be provided in the manuscript.

Field-specific reporting Please select the one below that is the best fit for your research. If you are not sure, read the appropriate sections before making your selection.

Life sciences

Behavioural & social sciences

Ecological, evolutionary & environmental sciences For a reference copy of the document with all sections, see nature.com/documents/nr-reporting-summary-flat.pdf Life sciences study design All studies must disclose on these points even when the disclosure is negative.

Sample size Data exclusions

Genomic and radiocarbon data from nine ancient individuals from Morocco were analysed in this study. The sample size was dependent on the availability of human remains dating to the Stone Age from northwestern Africa, with preserved and retrievable ancient DNA sequences. These specimens are very rare, given the poor molecular preservation of human remains from this period in that region. Given the millions of genetic variants analysed for each individual, information about the genetic history can be retrieved.

Reads shorter than 35 base pairs (bp), with more than 10% mismatch from the Reference genome and mapping quality score below 30 were discarded while preparing bamfiles for merged genomic libraries data. For samples not subjected to Uracil-Specific Excision Reagent (USER) treatment, 10 bp at the reads ends were excluded. For samples with partial treatment (comparative dataset) 2 bp were trimmed off of the reads ends. For analyses, minimum mapping and read qualities were set to 30. Pseudohaploid dataset was generated by randomly drawing one read at each SNP site, and that allele assumed to be homozygous. LD pruning for ADMIXTURE resulted in a reduction of the number of analysed SNPs (originally 1,379,466) to 812,092. When pairs of first-degree relatives (of comparative populations) were found, the individual with lower genomic coverage of the pair was excluded from analysis. Diploid dataset was generated with samples with a minimum of 9x genomic coverage. For MSMC's implementation of PSMC', minimum mapping quality of 30 and minimum genotype quality of 50 were used. For phenotypic analysis, genotype likelihoods were computed based on minimum mapping and read quality of 30 and read depth of 5. Several DNA extracts and multiple genomic libraries were generated for each sample (as reported in Table S1), and several rounds of sequencing were performed for each library (as reported in Supplementary Data File 15) as replication. Data was merged for downstream analysis after confirming similar results, as expected of different replicates of the same individual's genomic data, such as contamination estimates, mitochondrial haplogroup. Thousands to millions of genetic markers were then analysed as an internal replication of the results. Detailed description of the methods used, including samples included in the dataset, software employed and respective parameters is available in the Supplementary Information.

Randomization is not applicable to this study. Samples were grouped according to the archaeological site of origin and radiocarbon date. Groups are validated by verifying genetic affinities among its several individuals.

Blinding is not applicable to this study. The archaeological context, including site location and estimated date, of each individual analysed is known prior to sampling and analysis, as these are relevant for conceiving the study. Reporting for specific materials, systems and methods We require information from authors about some types of materials, experimental systems and methods used in many studies. Here, indicate whether each material, system or method listed is relevant to your study. If you are not sure if a list item applies to your research, read the appropriate section before selecting a response. Materials & experimental systems n/a Involved in the study

Methods n/a Involved in the study Antibodies Eukaryotic cell lines Palaeontology and archaeology Animals and other organisms Clinical data

Dual use research of concern Palaeontology and Archaeology Specimen provenance Specimen deposition Dating methods

Archaeological samples were excavated in Morocco at the archaeological sites of Ifri Ouberrid, Kaf Taht el Ghar, Ifri n’Amr ou Moussa and Skhirat-Rouazi Necropolis. Appropriate permits were obtained to conduct sampling and export archaeological material from the Institut National des Sciences de l´Archèologie et du Patrimoine (INSAP) in Rabat, Morocco.

The Institut National des Sciences de l´Archèologie et du Patrimoine (INSAP) in Rabat, Morocco is the sole curator of the specimens.

All individuals were directly radiocarbon dated using accelerator mass spectrometry (AMS) at the Tandem Laboratory at Ångström, Uppsala, except for ktg001, which was dated at the Beta Analytic Carbon dating laboratory and iam004, which date was obtained from the literature. Radiocarbon calibration was performed using OxCal v.4.4 and the IntCal20 dataset.

Tick this box to confirm that the raw and calibrated dates are available in the paper or in Supplementary Information.

Ethics oversight

Permits for sampling and analyses of the archaeological material were obtained from the appropriate institutions.

Note that full information on the approval of the study protocol must also be provided in the manuscript.

Animals and other research organisms Policy information about studies involving animals; ARRIVE guidelines recommended for reporting animal research, and Sex and Gender in Research

Laboratory animals Wild animals Reporting on sex Field-collected samples Ethics oversight n/a

The sex of the individuals for which archaeological remains were analysed was determined based on the ratio of coverage of the X chromosome and Y chromosome relative to the autosomes.

Linstädter , J. , Medved , I. , Solich , M. & Weniger , G.-C. Neolithisation process within the Alboran territory: models and possible African impact . Quat. Int . 274 , 2193232 ( 2012 ). Martínez-Sánchez , R. M. , Vera-Rodríguez , J. C. , Pérez-Jordà , G. , Peña-Chocarro , L. & Bokbot , Y. The beginning of the Neolithic in northwestern Morocco . Quat. Int . 470 , 4853496 ( 2018 ). 3. Zilhão , J. Early prehistoric navigation in the Western Mediterranean: implications for the Neolithic transition in Iberia and the Maghreb . Isl. Archaeol. Orig. Seafaring East. Mediterr . 11 , 1853200 ( 2014 ). 4. Mulazzani , S. et al. The emergence of the Neolithic in North Africa: a new model for the Eastern Maghreb . Quat. Int . 410 , 1233143 ( 2016 ). 5. Linstädter , J. The Epipalaeolithic-Neolithic-Transition in the Mediterranean region of Northwest Africa . Quartär. International Yearbook for Ice Age and Stone Age Research 55 , 41362 ( 2008 ). 6. Fregel , R. et al. Ancient genomes from North Africa evidence prehistoric migrations to the Maghreb from both the Levant and Europe . Proc. Natl Acad. Sci. USA 115 , 677436779 ( 2018 ). 7. Henn , B. M. et al. Genomic ancestry of North Africans supports back-to-Africa migrations . PLoS Genet . 8 , e1002397 ( 2012 ). 8. Arauna , L. R. et al. Recent historical migrations have shaped the gene pool of Arabs and Berbers in North Africa . Mol. Biol. Evol . 34 , 3183329 ( 2017 ). 9. Hublin , J.-J. et al. New fossils from Jebel Irhoud, Morocco and the pan-African origin of Homo sapiens . Nature 546 , 2893292 ( 2017 ). 10. van de Loosdrecht, M. et al. Pleistocene North African genomes link Near Eastern and sub-Saharan African human populations . Science 360 , 5483552 ( 2018 ). 11. Skoglund , P. et al. Origins and genetic legacy of Neolithic farmers and hunter-gatherers in Europe . Science 336 , 4663469 ( 2012 ). 12. Omrak , A. et al. Genomic evidence establishes Anatolia as the source of the European Neolithic gene pool . Curr. Biol . 26 , 2703275 ( 2016 ). 13. Antonio, M. L. et al. Ancient Rome: a genetic crossroads of Europe and the Mediterranean . Science 366 , 7083714 ( 2019 ). 14. Yu , H. et al. Genomic and dietary discontinuities during the Mesolithic and Neolithic in Sicily . iScience 25 , 104244 ( 2022 ). 15. Günther , T. et al. Ancient genomes link early farmers from Atapuerca in Spain to modern-day Basques . Proc. Natl Acad. Sci. USA 112 , 11917311922 ( 2015 ). 16. Barnett , W. K. Cardial pottery and the agricultural transition inMediterranean Europe . In Europe's First Farmers 933116 (Cambridge Univ. Press, 2000 ). 17. Manen , C. et al. The Neolithic transition in the Western Mediterranean: a complex and non-linear diffusion process4the radiocarbon record revisited . Radiocarbon 61 , 5313571 ( 2019 ). 18. Natali , E. & Forgia , V. The beginning of the Neolithic in Southern Italy and Sicily . Quat. Int . 470 , 2533269 ( 2018 ). 19. Guilaine , J. A personal view of the neolithisation of the Western Mediterranean . Quat. Int . 470 , 2113225 ( 2018 ). 20. Bernabeu Auban , J. & Pardo-Gordó , S. La impressa en la península Ibérica: ¿Espejismo o realidad? Una reflexión a partir del binomio radiocarbono-cerámica ( 2020 ) 21. Linstädter , J. , Broich , M. & Weninger , B. Defining the Early Neolithic of the Eastern Rif, Morocco3spatial distribution, chronological framework and impact of environmental changes . Quat. Int . 472 , 2723282 ( 2018 ). 22. Broodbank , C. & Lucarini , G. The dynamics of Mediterranean Africa, ca. 960031000 BC: an interpretative synthesis of knowns and unknowns . J. Mediterr . Archaeol. https://doi.org/ 10.17863/CAM.49028 ( 2020 ). 23. Martínez-Sánchez , R. M. et al. Reflections on the other side. A Southern Iberia origin for the first pottery production of Northern Morocco? Open Archaeol . 7 , 105431065 ( 2021 ). 24. Huysecom , E. et al. The emergence of pottery in Africa during the tenth millennium cal BC: new evidence from Ounjougou (Mali) . Antiquity 83 , 9053917 ( 2009 ). 25. Garcea , E. A. A. Semi-permanent foragers in semi-arid environments of North Africa . World Archaeol. 38 , 1973219 ( 2006 ). 26. Dunne , J. , Mercuri , A. M. , Evershed , R. P. , Bruni , S. & di Lernia , S. Earliest direct evidence of plant processing in prehistoric Saharan pottery . Nature Plants 3 , 16194 ( 2016 ). 27. Marshall , F. & Hildebrand , E. Cattle before crops: the beginnings of food production in Africa . J. World Prehist. 16 , 993143 ( 2002 ). 28. Gautier , A. In Droughts, Food and Culture: Ecological Change and Food Security in Africa's Later Prehistory (ed. Hassan , F. A. ) 1953207 ( Springer US , 2002 ); https://doi.org/10.1007/0- 306-47547-2_ 12 . 29. David , B. & McNiven , I. J. The Oxford Handbook of the Archaeology and Anthropology of Rock Art (Oxford Univ . Press, 2018 ). 30. Smith , A. B. Origins and spread of pastoralism in Africa . Annu. Rev. Anthropol . 21 , 1253141 ( 1992 ). 31. Olalde , I. et al. The genomic history of the Iberian Peninsula over the past 8000 years . Science 363 , 123031234 ( 2019 ). 32. Valdiosera , C. et al. Four millennia of Iberian biomolecular prehistory illustrate the impact of prehistoric migrations at the far end of Eurasia . Proc. Natl Acad. Sci. USA 115 , 342833433 ( 2018 ). 33. Villalba-Mouco , V. et al. Survival of Late Pleistocene hunter-gatherer ancestry in the Iberian Peninsula . Curr. Biol . 29 , 116931177 ( 2019 ). 34. Mallick , S. et al. The Simons Genome Diversity Project: 300 genomes from 142 diverse populations . Nature 538 , 2013206 ( 2016 ). 35. Humphrey , L. T. et al. Earliest evidence for caries and exploitation of starchy plant foods in Pleistocene hunter-gatherers from Morocco . Proc. Natl Acad. Sci. USA 111 , 9543959 ( 2014 ). 36. Turek , J. & Vintr , J. Neolit Maghrebu ve sv tle nových radiokarbonových dat . i}vá Archeol . 18 , 10315 ( 2016 ). 37. Ringbauer , H. , Novembre , J. & Steinrücken , M. Parental relatedness through time revealed by runs of homozygosity in ancient DNA . Nat. Commun . 12 , 5425 ( 2021 ). 38. Morales , J. et al. The introduction of South-Western Asian domesticated plants in NorthWestern Africa: an archaeobotanical contribution from Neolithic Morocco . Quat. Int . 412 , 963109 ( 2016 ). 39. Martínez Sánchez , R. M. et al. Revisiting the Epipalaeolithic-Neolithic Transition in the extreme NW of Africa: the latest results of the chronological sequence of the Cave of Kaf Taht el-Ghar (Tétouan, Morocco) . Afr. Archaeol. Rev . 38 , 2513274 ( 2021 ). 40. Lipson , M. et al. Parallel palaeogenomic transects reveal complex genetic history of early European farmers . Nature 551 , 3683372 ( 2017 ). 41. Reimer , P. J. et al. The IntCal20 Northern Hemisphere radiocarbon age calibration curve (0355 cal kBP) . Radiocarbon 62 , 7253757 ( 2020 ). 42. Martins , H. et al. Radiocarbon dating the beginning of the Neolithic in Iberia: new results, new problems . J. Mediterr. Archaeol . 28 , 1053131 ( 2015 ). 43. García Borja , P. , Aura Tortosa , J. E. , Bernabeu Aubán , J. & Jordá Pardo , J. F. Nuevas perspectivas sobre la neolitización en la cueva de Nerja (Málaga-España): la cerámica de la sala del vestíbulo . Zephyrvs https://revistas.usal.es/uno/index.php/0514-7336/article/ view/7979/8431 ( 2010 ). 44. Marcus , J. H. et al. Genetic history from the Middle Neolithic to present on the Mediterranean island of Sardinia . Nat. Commun . 11 , 939 ( 2020 ). 45. Mathieson , I. et al. The genomic history of southeastern Europe . Nature 555 , 1973203 ( 2018 ). 46. Prendergast , M. E. et al. Ancient DNA reveals a multistep spread of the first herders into sub-Saharan Africa . Science 365 , eaaw6275 ( 2019 ). 47. Martínez Sánchez , R. M. et al. The Middle Neolithic of Morocco's North-Western Atlantic Strip: new evidence from the El-Khil Caves (Tangier) . Afr. Archaeol. Rev . 35 , 4173442 ( 2018 ). 48. Gilman , A. The Later Prehistory of Tangier, Morocco (American School of Prehistoric Research, Peabody Museum of Archaeology and Ethnology , Harvard Univ., 1975 ). 49. Rodríguez-Varela , R. et al. Genomic analyses of pre-European conquest human remains from the Canary Islands reveal close affinity to modern North Africans . Curr. Biol . 27 , 339633402 ( 2017 ). 50. Moots , H. M. et al. A genetic history of continuity and mobility in the Iron Age Central Mediterranean . Preprint at bioRxiv https://doi.org/10.1101/ 2022 .03.13.483276 ( 2022 ). 53. Svensson , E. et al. Genome of Pe_tera Muierii skull shows high diversity and low mutational load in pre-glacial Europe . Curr. Biol . 31 , 297332983 ( 2021 ). 54. Meyer, M. & Kircher , M. Illumina sequencing library preparation for highly multiplexed target capture and sequencing . Cold Spring Harb. Protoc . 2010 , pdb- prot5448 ( 2010 ). 55. Günther , T. et al. Population genomics of Mesolithic Scandinavia: investigating early postglacial migration routes and high-latitude adaptation . PLoS Biol . 16 , e2003703 ( 2018 ). 56. Gansauge , M.-T. & Meyer, M. Single-stranded DNA library preparation for the sequencing of ancient or damaged DNA . Nat. Protoc . 8 , 7373748 ( 2013 ). 57. Kircher , M. Analysis of high-throughput ancient DNA sequencing data . Methods Mol. Biol . 840 , 1973228 . 58. Schubert , M. , Lindgreen , S. & Orlando , L. AdapterRemoval v2: rapid adapter trimming, identification, and read merging . BMC Res. Notes 9 , 88 ( 2016 ). 59. Li , H. & Durbin , R. Fast and accurate short read alignment with Burrows3Wheeler transform . Bioinformatics 25 , 175431760 ( 2009 ). 60. Li , H. et al. The sequence alignment/map format and SAMtools . Bioinformatics 25 , 207832079 ( 2009 ). 51. Yang , D. Y. , Eng , B. , Waye , J. S. , Dudar , J. C. & Saunders , S. R. Improved DNA extraction from ancient bones using silica-based spin columns . Am. J. Phys. Anthropol . 105 , 5393543 ( 1998 ). 52. Dabney , J. et al. Complete mitochondrial genome sequence of a Middle Pleistocene cave bear reconstructed from ultrashort DNA fragments . Proc. Natl Acad. Sci. USA 110 , 15758315763 ( 2013 ). Acknowledgements We thank A. R. Munters for bioinformatics support and R. P. Stjerna and F. Sánchez-Quinto for helpful discussions on data analysis. Sequencing was performed at The National Genomics Infrastructure, Uppsala. Computations and data handling were enabled by resources provided by the Swedish National Infrastructure for Computing at the Uppsala Multidisciplinary Center for Advanced Computational Science, partially funded by the Swedish Research Council through grant agreement no. 2018 - 05973 . This project was supported by the Knut and Alice Wallenberg Foundation (to M.J .), Vetenskapsrådet (grant nos. 2018-05537 and 2022-04642 to M.J. and 2017-05267 to T.G.) and Ramón y Cajal (grant no. RYC2018-025223-I to C.V.). The Spanish3Moroccan archaeological team wassupported by the European Research Council (no . ERC AdG 230561).