While the series of events that shaped the transition between foraging societies and food producers are well described for Central and Southern Europe, genetic evidence from Northern Europe surrounding the Baltic Sea is still sparse. Here, we report genome-wide DNA data from 38 ancient North Europeans ranging from 9500 to 2200 years before present. Our analysis provides genetic evidence that hunter-gatherers settled Scandinavia via two routes. We reveal that the first Scandinavian farmers derive their ancestry from Anatolia 1000 years earlier than previously demonstrated. The range of Mesolithic Western hunter-gatherers extended to the east of the Baltic Sea, where these populations persisted without gene-flow from Central European farmers during the Early and Middle Neolithic. The arrival of steppe pastoralists in the Late Neolithic introduced a major shift in economy and mediated the spread of a new ancestry associated with the Corded Ware Complex in Northern Europe.