Modern humans have populated Europe for more than 45,000 years1,2. Our knowledge of the genetic relatedness and structure of ancient hunter-gatherers is however limited, owing to the scarceness and poor molecular preservation of human remains from that period3. Here we analyse 356 ancient hunter-gatherer genomes, including new genomic data for 116 individuals from 14 countries in western and central Eurasia, spanning between 35,000 and 5,000 years ago. We identify a genetic ancestry profile in individuals associated with Upper Palaeolithic Gravettian assemblages from western Europe that is distinct from contemporaneous groups related to this archaeological culture in central and southern Europe4, but resembles that of preceding individuals associated with the Aurignacian culture. This ancestry profile survived during the Last Glacial Maximum (25,000 to 19,000 years ago) in human populations from southwestern Europe associated with the Solutrean culture, and with the following Magdalenian culture that re-expanded northeastward after the Last Glacial Maximum. Conversely, we reveal a genetic turnover in southern Europe suggesting a local replacement of human groups around the time of the Last Glacial Maximum, accompanied by a north-to-south dispersal of populations associated with the Epigravettian culture. From at least 14,000 years ago, an ancestry related to this culture spread from the south across the rest of Europe, largely replacing the Magdalenian-associated gene pool. After a period of limited admixture that spanned the beginning of the Mesolithic, we find genetic interactions between western and eastern European hunter-gatherers, who were also characterized by marked differences in phenotypically relevant variants.