BackgroundMetformin, a type 2 diabetes treatment, improves the cognitive function of aged mice; however, whether the protective effects of metformin on cognitive function in aged mice are associated with the gut microbiome is poorly understood. Although some studies suggest that the gut microbe composition influences cognitive function and that manipulating the gut microbiota might protect against age-related cognitive dysfunction, there is no direct evidence to validate that the gut microbiota mediates the effect of metformin on cognitive improvement.ResultsIn this study, we show that the gut microbiota is altered by metformin, which is necessary for protection against ageing-associated cognitive function declines in aged mice. Mice treated with antibiotics did not exhibit metformin-mediated cognitive function protection. Moreover, treatment withAkkermansia muciniphila,which is enriched by metformin, improved cognitive function in aged mice. Mechanistically,A. muciniphiladecreased pro-inflammatory-associated pathways, particularly that of the pro-inflammatory cytokine interleukin (IL)-6, in both the peripheral blood and hippocampal profiles, which was correlated with cognitive function improvement. An IL-6 antibody protected cognitive function, and an IL-6 recombinant protein abolished the protective effect ofA. muciniphilaon cognitive function in aged mice.ConclusionThis study reveals thatA. muciniphila, which is mediated in the gut microbiota by metformin, modulates inflammation-related pathways in the host and improves cognitive function in aged mice by reducing the pro-inflammatory cytokine IL-6.Video AbstractGraphical AbstractSupplementary InformationThe online version contains supplementary material available at 10.1186/s40168-023-01567-1.