Dispersal, one of the key life-history features of a species, influences gene flow and, consequently, the genetic structuring of populations. Landscape characteristics such as rivers, mountains, or habitat fragmentation affect dispersal and result in broad-scale genetic structuring of various mammalian species [1, 2, 3, 4, 5]. However, less attention has been paid to studying how dispersal is influenced by finer-scale microgeographic variation in a continuous habitat. Here we investigate the genetic structure of a closed population of ∼300 endangered mountain gorillas living in multiple groups in a small (331 km2) forest in southwestern Uganda. In a species in which both sexes routinely disperse, population genetic structure in females was influenced by distance, altitude, and plant community composition, whereas males were not geographically structured. The effect of distance fits the observed tendency of females to transfer to neighboring groups, whereas the effects of altitude and vegetation reflect the changing species composition of locally available food resources. These results suggest that individual dietary preferences are important even in a highly mobile species living amid abundant food, and we propose that preference for natal habitats will influence dispersal decisions in many other vertebrate taxa.