Metformin is widely used in the treatment of type 2 diabetes (T2D), but its mechanism of action is poorly defined. Recent evidence implicates the gut microbiota as a site of metformin action. In a double-blind study, we randomized individuals with treatment-naive T2D to placebo or metformin for 4 months and showed that metformin had strong effects on the gut microbiome. These results were verified in a subset of the placebo group that switched to metformin 6 months after the start of the trial. Transfer of fecal samples (obtained before and 4 months after treatment) from metformin-treated donors to germ-free mice showed that glucose tolerance was improved in mice that received metformin-altered microbiota. By directly investigating metformin-microbiota interactions in a gut simulator, we showed that metformin affected pathways with common biological functions in species from two different phyla, and many of the metformin-regulated genes in these species encoded metalloproteins or metal transporters. Our findings provide support for the notion that altered gut microbiota mediates some of metformin's antidiabetic effects.