Gut microbiota is becoming one of the key determinants in human health and disease. Shifts in gut microbiota composition affect cognitive function and provide new insights for the prevention and treatment of neurological diseases. Diabetes-associated cognitive decline (DACD) is one of the central nervous system complications of type 2 diabetes mellitus (T2DM). ZiBuPiYin recipe (ZBPYR), a traditional Chinese medicine (TCM) formula, has long been used for the treatment of T2DM and prevention of DACD. However, the contribution of ZBPYR treatment to the interaction between the gut microbiota and metabolism for preventing and treating DACD remains to be clarified. Here, we investigate whether the gut microbiota plays a key role in ZBPYR-mediated prevention of DACD and treatment of T2DM via incorporating microbiomics and metabolomics, and investigate the links between the microbiota–gut–brain axis interaction and the efficacy of ZBPYR in ZDF rats. In the current study, we found that ZBPYR treatment produced lasting changes in gut microbiota community and metabolites and remotely affected hippocampus metabolic changes, thereby improving memory deficits and reversing β-amyloid deposition and insulin resistance in the brain of ZDF rats from T2DM to DACD. This may be related to a series of metabolic changes affected by gut microbiota, including alanine, aspartic acid, and glutamic acid metabolism; branched-chain amino acid metabolism; short-chain fatty acid metabolism; and linoleic acid/unsaturated fatty acid metabolism. In summary, this study demonstrates that prevention and treatment of DACD by ZBPYR partly depends on the gut microbiota, and the regulatory effects of bacteria-derived metabolites and microbiota–gut–brain axis are important protective mechanisms of ZBPYR.