Diabetic cognitive impairment (DCI) is a serious neurodegenerative disorder caused by diabetes, with chronic inflammation being a crucial factor in its pathogenesis. Pterostilbene is a well‐known natural stilbene derivative that has excellent anti‐inflammatory activity, suggesting its potential medicinal advantages for treating DCI. Therefore, this study is to explore the beneficial effects of pterostilbene for improving cognitive dysfunction in DCI mice. A diabetic model was induced by a high‐fat diet plus streptozotocin (40 mg·kg−1) for consecutive 5 days. After the animals were confirmed to be in a diabetic state, they were treated with pterostilbene (20 or 60 mg·kg−1, i.g.) for 10 weeks. Pharmacological evaluation showed pterostilbene could ameliorate cognitive dysfunction, regulate glycolipid metabolism disorders, improve neuronal damage, and reduce the accumulation of β‐amyloid in DCI mice. Pterostilbene alleviated neuroinflammation by suppressing oxidative stress and carbonyl stress damage, astrocyte and microglia activation, and dopaminergic neuronal loss. Further investigations showed that pterostilbene reduced the level of lipopolysaccharide, modulated colon and brain TLR4/NF‐κB signaling pathways, and decreased the release of inflammatory factors, which in turn inhibited intestinal inflammation and neuroinflammation. Furthermore, pterostilbene could also improve the homeostasis of intestinal microbiota, increase the levels of short‐chain fatty acids and their receptors, and suppress the loss of intestinal tight junction proteins. In addition, the results of plasma non‐targeted metabolomics revealed that pterostilbene could modulate differential metabolites and metabolic pathways associated with inflammation, thereby suppressing systemic inflammation in DCI mice. Collectively, our study found for the first time that pterostilbene could alleviate diabetic cognitive dysfunction by inhibiting the TLR4/NF‐κB pathway through the microbiota‐gut‐brain axis, which may be one of the potential mechanisms for its neuroprotective effects.