Diet-induced obesity is a global phenomenon that affects the population worldwide with manifestations at both the phenotypic and genotypic levels. Cognitive function decline is a major global health challenge. The relation between obesity and cognitive function is a debatable issue. The main goal of the current research was to study the implications of obesity on cognitive function and gut microbiota diversity and its impact on plasma and brain metabolic parameters in rats. Obesity was induced in rats by feeding on a high-fat (HF) or a high-fat/high-sucrose (HFHS) diet. The results reveal that both the HF (0.683) and HFHS (0.688) diets were effective as obesity inducers, which was confirmed by a significant increase in the body mass index (BMI). Both diet groups showed dyslipidemia and elevation of oxidative stress, insulin resistance (IR), and inflammatory markers with alterations in liver and kidney functions. Obesity led to a reduction in cognitive function through a reduction in short-term memory by 23.8% and 30.7% in the rats fed HF and HFHS diets, respectively, and learning capacity and visuo-spatial memory reduced by 8.9 and 9.7 s in the rats fed an HF or HFHS diet, respectively. Bacteroidetes, Firmicutes, Proteobacteria, Fusobacteria, and Spirochaetes phyla were detected. The Firmicutes/Bacteroidetes ratio (F/B) significantly decreased in the HF group, while it increased in the HFHS group compared to the normal control. The two species, Bacteroides acidifaciens and Bacteroides ovatus, which are associated with IR, were drastically compromised by the high-fat/high-sucrose diet. Some species that have been linked to reduced inflammation showed a sharp decrease in the HFHS group, while Prevotella copri, which is linked to carbohydrate metabolism, was highly enriched. In conclusion: Obesity led to cognitive impairment through changes in short-term and visuo-spatial memory. A metagenomic analysis revealed alterations in the abundance of some microbial taxa associated with obesity, inflammation, and insulin resistance in the HF and HFHS groups.