Surgery can induce cognitive decline, a risk that increases with advancing age. In rodents, postoperative cognitive decline (POCD) is associated with the inflammatory activation of hippocampal microglia. To examine the role of microglia in POCD, we inhibited the colony-stimulating factor 1 receptor (CSF1R) in adult mice, effectively depleting CNS microglia. Surgical trauma (tibial fracture) reduced the ability of mice to remember a conditioned response learned preoperatively, a deficit more pronounced and persistent in mice with diet-induced obesity (DIO). Whereas microglial depletion by itself did not affect learning or memory, perioperative microglial depletion remarkably protected mice, including those with DIO, from POCD. This protection was associated with reduced hippocampal levels of inflammatory mediators, abrogation of hippocampal recruitment of CCR2+ leukocytes, and higher levels of circulating inflammation-resolving factors. Targeting microglia may thus be a viable strategy to mitigate the development of POCD, particularly in those with increased vulnerability.