Cryptic population structure in exploited fish species poses a major challenge for fisheries management. Atlantic cod (Gadus morhua) is a species in which the presence of sympatric ecotypes has been known for a long time, for instance off the coast of Northern Norway. More recently, two sympatric ecotypes of cod have also been documented in the Skagerrak and Kattegat; one ecotype is of an apparent offshore origin and undertakes spawning migrations to the North Sea, and the other is resident at the coast throughout its life. However, their relative contributions of juveniles to the Swedish west coast remain poorly understood. The lack of adult cod along the Skagerrak and Kattegat coasts in recent years has led to the hypothesis that the offshore ecotype is the main source of juveniles to the area, but recent studies have shown large proportions of coastal cod inside Norwegian Skagerrak fjords. In this study, juvenile cod were collected at a high spatial resolution along the Swedish west coast, and genetically assigned to each of the two ecotypes. The results reveal that there is a considerable proportion of juvenile coastal cod in the southern Kattegat, Öresund, and in inshore Swedish Skagerrak, but that the offshore ecotype dominates in offshore areas. Model selection suggests that differences in bottom depth, rather than distance from the open sea, may explain the heterogenous spatial distribution of the two ecotypes. In addition, the two ecotypes displayed differences at loci known to be associated with environmental adaptation, suggesting that their spatial distribution is maintained by natural selection in response to specific environmental conditions.