The anti-hyperglycemic effect of metformin is believed to be caused by its direct action on signaling processes in hepatocytes, leading to lower hepatic gluconeogenesis. Recently, metformin was reported to alter the gut microbiota community in humans, suggesting that the hyperglycemia-lowering action of the drug could be the result of modulating the population of gut microbiota. However, the critical microbial signaling metabolites and the host targets associated with the metabolic benefits of metformin remained elusive. Here, we performed metagenomic and metabolomic analysis of samples from individuals with newly diagnosed type 2 diabetes (T2D) naively treated with metformin for 3 d, which revealed that Bacteroides fragilis was decreased and the bile acid glycoursodeoxycholic acid (GUDCA) was increased in the gut. These changes were accompanied by inhibition of intestinal farnesoid X receptor (FXR) signaling. We further found that high-fat-diet (HFD)-fed mice colonized with B. fragilis were predisposed to more severe glucose intolerance, and the metabolic benefits of metformin treatment on glucose intolerance were abrogated. GUDCA was further identified as an intestinal FXR antagonist that improved various metabolic endpoints in mice with established obesity. Thus, we conclude that metformin acts in part through a B. fragilis-GUDCA-intestinal FXR axis to improve metabolic dysfunction, including hyperglycemia.