Accumulating evidence suggests that the gut microbiota is an important factor in mediating the development of obesity-related metabolic disorders, including type 2 diabetes. Metformin and berberine, two clinically effective drugs for treating diabetes, have recently been shown to exert their actions through modulating the gut microbiota. In this study, we demonstrated that metformin and berberine similarly shifted the overall structure of the gut microbiota in rats. Both drugs showed reverting effects on the high-fat diet-induced structural changes of gut microbiota. The diversity of gut microbiota was significantly reduced by both berberine- and metformin-treatments. Nearest shrunken centroids analysis identified 134 operational taxonomic units (OTUs) responding to the treatments, which showed close associations with the changes of obese phenotypes. Sixty out of the 134 OTUs were decreased by both drugs, while those belonging to putative short-chain fatty acids (SCFA)-producing bacteria, including Allobaculum, Bacteriodes, Blautia, Butyricoccus, and Phascolarctobacterium, were markedly increased by both berberine and, to a lesser extent, metformin. Taken together, our findings suggest that berberine and metformin showed similarity in modulating the gut microbiota, including the enrichment of SCFA-producing bacteria and reduction of microbial diversity, which may contribute to their beneficial effects to the host.