Southwest China is a biodiversity hotspot characterized by complex topography, heterogeneous regional climates and rich flora. The processes and driving factors underlying this hotspot remain to be explicitly tested across taxa to gain a general understanding of the evolution of biodiversity and speciation in the region. In this study, we examined the role played by historically neutral processes, geography and environment in producing the current genetic diversity of the subtropical pine Pinus yunnanensis. We used genetic and ecological methods to investigate the patterns of genetic differentiation and ecological niche divergence across the distribution range of this species. We found both continuous genetic differentiation over the majority of its range, and discrete isolated local clusters. The discrete differentiation between two genetic groups in the west and east peripheries is consistent with niche divergence and geographical isolation of these groups. In the central area of the species’ range, population structure was shaped mainly by neutral processes and geography rather than by ecological selection. These results show that geographical and environmental factors together created stronger and more discrete genetic differentiation than isolation by distance alone, and illustrate the importance of ecological factors in forming or maintaining genetic divergence across a complex landscape. Our findings differ from other phylogenetic studies that identified the historical drainage system in the region as the primary factor shaping population structure, and highlight the heterogeneous contributions that geography and environment have made to genetic diversity among taxa in southwest China.