Background: A ketogenic diet (KD), which is extremely high in fat with a very low carbohydrate level and can induce changes in gut microbiota, has shown benefits for epilepsy and several neurodegenerative diseases. However, the effects of a KD on glucose and lipid metabolism remain inconclusive.Results: Using two formulas of ketogenic diets (KDR with 89.5% fat and KDH with 91.3% fat), which are commonly used in mouse trials, we found that KDR but not KDH induced insulin resistance and damaged glucose homeostasis, while KDH induced more fat accumulation in mice. In addition to the differences in the proportions of nutrients between the two kinds of KD, we found that the sources of fat in KDR were mainly trans-fatty acids. Further study showed that KD impacted glucose metabolism, which was related to the sources of fat, while both the sources and proportions of fat affected lipid metabolism. We found that both the sources and proportions of fat changed the abundance of specific bacteria in Lachnospiraceae and Oscillibacter, which positively correlated with parameters related to lipid accumulation. The abundances of specific bacteria in Bacteroides and Ruminococcaceae were only affected by the sources of fat, and specific bacteria from Lactococcus and Roseburia were only affected by the proportions of fat. Moreover, alterations in the concentrations of SCFAs and tryptophan metabolites, which were negatively correlated with parameters related to lipid accumulation, were also affected by the sources of fat. In addition, the ketogenic diet widely used in human studies still induced insulin resistance and fat accumulation in mice; enhanced Roseburia, Ruminococcaceae and Lachnospiraceae; reduced Turicibacter; increased bile acids and decreased SCFAs.Conclusions: Overall, our study demonstrated that ketogenic diets induced glucose intolerance and lipid accumulation in mice, which is closely related to the source and proportion of fat in the diet, likely due to changes in the gut microbiota and metabolites.