The animal gut microbiome has been implicated in a number of key biological processes, ranging from digestion to behaviour, and has also been suggested to facilitate local adaptation. Yet studies in wild animals rarely compare multiple populations that differ ecologically, which is the level at which local adaptation may occur. Further, few studies simultaneously characterize diet and gut microbiome from the same sample, despite their probable interdependence. Here, we investigate the interplay between diet and gut microbiome in three geographically isolated populations of the critically endangered Grauer's gorilla (Gorilla beringei graueri), which we show to be genetically differentiated. We find population- and social group-specific dietary and gut microbial profiles and covariation between diet and gut microbiome, despite the presence of core microbial taxa. There was no detectable effect of age, and only marginal effects of sex and genetic relatedness on the microbiome. Diet differed considerably across populations, with the high-altitude population consuming a lower diversity of plants compared to low-altitude populations, consistent with plant availability constraining dietary choices. The observed pattern of covariation between diet and gut microbiome is probably a result of long-term social and environmental factors. Our study suggests that the gut microbiome is sufficiently plastic to support flexible food selection and hence contribute to local adaptation.