Understanding how specific environmental factors shape gene flow while disentangling their importance relative to the effects of geographical isolation is a major question in evolutionary biology and a specific goal of landscape genetics. Here, we combine information from nuclear microsatellite markers and ecological niche modelling to study the association between climate and spatial genetic structure and variability in Engelmann oak (Quercus engelmannii), a wind-pollinated species with high potential for gene flow. We first test whether genetic diversity is associated with climatic niche suitability and stability since the Last Glacial Maximum (LGM). Second, we use causal modelling to analyse the potential influence of climatic factors (current and LGM niche suitability) and altitude in the observed patterns of genetic structure. We found that genetic diversity is negatively associated with local climatic stability since the LGM, which may be due to higher immigration rates in unstable patches during favourable climatic periods and/or temporally varying selection. Analyses of spatial genetic structure revealed the presence of three main genetic clusters, a pattern that is mainly driven by two highly differentiated populations located in the northern edge of the species distribution range. After controlling for geographic distance, causal modelling analyses showed that genetic relatedness decreases with the environmental divergence among sampling sites estimated as altitude and current and LGM niche suitability. Natural selection against nonlocal genotypes and/or asynchrony in reproductive phenology may explain this pattern. Overall, this study suggests that local environmental conditions can shape patterns of genetic structure and variability even in species with high potential for gene flow and relatively small distribution ranges.