Globally, cognitive impairment (CI) is the leading cause of disability and dependency among the elderly, presenting a significant public health concern. However, there is currently a deficiency in pharmacological interventions that can effectively cure or significantly reverse the progression of cognitive impairment. Methyl donor nutrients (MDNs), including folic acid, choline, and vitamin B12, have been identified as potential enhancers of cognitive function. Nevertheless, there remains a dearth of comprehensive research investigating the connection between the dietary intake of MDNs and CI. In our study, we comprehensively assessed the relationship between MDNs’ dietary intake and CI in older adults, utilizing 16S rRNA gene sequencing to investigate the potential underlying mechanisms. The results showed an obvious difference in the methyl-donor nutritional quality index (MNQI) between the dementia (D) group and the dementia-free (DF) group. Specifically, there was a lower MNQI in the D group than that in the DF group. For the gut microbiome, the beta diversity of gut flora exhibited higher levels in the high methyl-donor nutritional quality (HQ) group as opposed to the low methyl-donor nutritional quality (LQ) group, and lower levels in the D group in comparison to the DF group. Subsequently, we performed a correlation analysis to examine the relationship between the relative abundance of microbiota, the intake of MDNs, and Montreal Cognitive Assessment (MoCA) scores, ultimately identifying ten genera with potential regulatory functions. Additionally, KEGG pathway analyses suggested that the one-carbon metabolism, chronic inflammation, and DNA synthesis potentially serve as pathways through which MDNs may be promising for influencing cognitive function. These results implied that MDNs might have the potential to enhance cognitive function through the regulation of microbiota homeostasis. This study offers dietary recommendations for the prevention and management of CI in the elderly.