This study investigated the effects of exercise on postoperative cognitive dysfunction (POCD) in mice. Surgery induced learning and memory impairment, which was transferable via fecal transplantation. Low-intensity exercise attenuated these effects by reducing gut microbiota changes and valeric acid levels. Valeric acid, a gut microbiota product, worsened neuroinflammation and cognitive function. Exercise also reduced neuroinflammation, maintained astrocytes in the A2 phenotype, and improved neuroplasticity. These benefits were observed in both adult and aged mice, highlighting the potential of low-intensity exercise as a therapeutic strategy for POCD.