Natural selection and ecological adaptation are ultimately responsible for much of the origin of biodiversity. Yet, the identification of divergent natural selection has been hindered by the spatial complexity of natural systems, the difficulty in identifying genes under selection and their relationship to environment, and the confounding genomic effects of time. Here, we employed genome scans, population genetics and sequence-based phylogeographic methods to identify divergent natural selection on population boundaries in a freshwater invader, the Amazonian pufferfish, Colomesus asellus. We sampled extensively across markedly different hydrochemical settings in the Amazon Basin and use ‘water colour’ to test for ecological isolation. We distinguish the relative contribution of natural selection across hydrochemical gradients from biogeographic history in the origin and maintenance of population boundaries within a single species and across a complex ecosystem. We show that spatially distinct population structure generated by multiple forces (i.e. water colour and vicariant biogeographic history) can be identified if the confounding effects of genetic drift have not accumulated between selective populations. Our findings have repercussions for studies aimed at identifying engines of biodiversity and assessing their temporal progression in understudied and ecologically complex tropical ecosystems.