Obesity is a risk factor for neurodegenerative disease associated with cognitive dysfunction, including Alzheimer’s disease. Low-grade inflammation is common in obesity, but the mechanism between inflammation and cognitive impairment in obesity is unclear. Accumulative evidence shows that quinolinic acid (QA), a neuroinflammatory neurotoxin, is involved in the pathogenesis of neurodegenerative processes. We investigated the role of QA in obesity-induced cognitive impairment and the beneficial effect of butyrate in counteracting impairments of cognition, neural morphology, and signaling. We show that in human obesity, there was a negative relationship between serum QA levels and cognitive function and decreased cortical gray matter. Diet-induced obese mice had increased QA levels in the cortex associated with cognitive impairment. At single-cell resolution, we confirmed that QA impaired neurons, altered the dendritic spine’s intracellular signal, and reduced brain-derived neurotrophic factor (BDNF) levels. Using Caenorhabditis elegans models, QA induced dopaminergic and glutamatergic neuron lesions. Importantly, the gut microbiota metabolite butyrate was able to counteract those alterations, including cognitive impairment, neuronal spine loss, and BDNF reduction in both in vivo and in vitro studies. Finally, we show that butyrate prevented QA-induced BDNF reductions by epigenetic enhancement of H3K18ac at BDNF promoters. These findings suggest that increased QA is associated with cognitive decline in obesity and that butyrate alleviates neurodegeneration.