Melatonin has been shown to improve lipid metabolism and gut microbiota communities in animals and humans; however, it remains to know whether melatonin prevents obesity through gut microbiota. Here, we found that high-fat diet promoted the lipid accumulation and intestinal microbiota dysbiosis in mice, while oral melatonin supplementation alleviated the lipid accumulation and reversed gut microbiota dysbiosis, including the diversity of intestinal microbiota, relative abundances of Bacteroides and Alistipes, and functional profiling of microbial communities, such as energy metabolism, lipid metabolism, and carbohydrate metabolism. Interestingly, melatonin failed to alleviate the high-fat-induced lipid accumulation in antibiotic-treated mice; however, microbiota transplantation from melatonin-treated mice alleviated high-fat diet-induced lipid metabolic disorders. Notably, short-chain fatty acids were decreased in high-fat diet-fed mice, while melatonin treatment improved the production of acetic acid. Correlation analysis found a marked correlation between production of acetic acid and relative abundances of Bacteroides and Alistipes. Importantly, sodium acetate treatment also alleviated high-fat diet-induced lipid metabolic disorders. Taken together, our results suggest that melatonin improves lipid metabolism in high-fat diet-fed mice, and the potential mechanisms may be associated with reprogramming gut microbiota, especially, Bacteroides and Alistipes-mediated acetic acid production. Future studies are needed for patients with metabolic syndrome to fully understand melatonin's effects on body weight and lipid profiles and the potential mechanism of gut microbiota.