The gut microbiomes of mammals appear to mirror their hosts' phylogeny, suggesting host-driven microbial community assembly. Yet, much of this evidence stems from comparative studies of distinct wild or captive populations that lack data for disentangling the relative influences of shared phylogeny and environment. Here, we present phylogenetic and multivariate analyses of gut microbiomes from six sympatric (i.e., co-occurring) mammal species inhabiting a 1-km 2 area in western Madagascar-three lemur and three non-primate species-that consider genetic, dietary, and ecological predictors of microbiome functionality and composition. Host evolutionary history, indeed, appears to shape gut microbial patterns among both closely and distantly related species. However, we also find that diet-reliance on leaves versus fruit-is the best predictor of microbiome similarity among closely related lemur species, and that host substrate use-ground versus tree -constrains horizontal transmission via incidental contact with feces, with arboreal species harboring far more distinct communities than those of their terrestrial and semi-terrestrial counterparts.