South America is home to the highest freshwater fish biodiversity on Earth, and the hotspot of species richness is located in the western Amazon basin. The location of this hotspot is enigmatic, as it is inconsistent with the pattern observed in river systems across the world of increasing species richness towards a river’s mouth. Here we investigate the role of river capture events caused by Andean mountain building and repeated episodes of flooding in western Amazonia in shaping the modern-day richness pattern of freshwater fishes in South America, and in Amazonia in particular. To this end, we combine a reconstruction of river networks since 80 Ma with a mechanistic model simulating dispersal, allopatric speciation and extinction over the dynamic landscape of rivers and lakes. We show that Andean mountain building and consequent numerous small river capture events in western Amazonia caused freshwater habitats to be highly dynamic, leading to high diversification rates and exceptional richness. The history of marine incursions and lakes, including the Miocene Pebas mega-wetland system in western Amazonia, played a secondary role.