Gene-environment interactions impact the development of neuropsychiatric disorders, but the relative contributions are unclear. Here, we identify gut microbiota as sufficient to induce depressive-like behaviors in genetically distinct mouse strains. Daily gavage of saline in non-obese diabetic (NOD) mice induced a social avoidance behavior that was not observed in C57BL/6 mice. This was not observed in NOD animals with depleted microbiota via oral administration of antibiotics. Transfer of intestinal microbiota, including members of the Clostridiales, Lachnospiraceae and Ruminococcaceae, from vehicle-gavaged NOD donors to microbiota-depleted C57BL/6 recipients was sufficient to induce social avoidance and change gene expression and myelination in the prefrontal cortex. Metabolomic analysis identified increased cresol levels in these mice, and exposure of cultured oligodendrocytes to this metabolite prevented myelin gene expression and differentiation. Our results thus demonstrate that the gut microbiota modifies the synthesis of key metabolites affecting gene expression in the prefrontal cortex, thereby modulating social behavior.