The impact of maternal surgery combined with general anesthesia on neuroinflammation and the development of learning and memory impairment in offspring remains unclear. This study utilized a pathogen-free laparotomy model to investigate these changes during the second trimester, as well as their response to anti-inflammatory therapy. C57BL/6 pregnant mice at the 14.5-day embryo stage (E 14.5) were either exposed to sevoflurane anesthesia alone or underwent laparotomy procedure. The neuroinflammatory response was evaluated at 7, 14, 21, and 28 days postnatal (P7, P14, P21, P28). Tau phosphorylation and cognitive ability were assessed at P28 and P30, respectively. The impact of perioperative administration of ibuprofen (60 mg/kg) on these aforementioned changes was subsequently evaluated. In the laparotomy group, levels of inflammatory factors (IL-4, IL-8, IL-17A, TGF-β, M-CSF, CCL2) in the brains of offspring mice, including the cerebral cortex and hippocampus, remained consistently elevated from P7 to P28. At P14, while the majority of inflammatory cytokine has no statistical difference, there was still a significant reactivation of inflammatory cytokines observed in the frontal cortex and hippocampus at P28. Furthermore, abnormal phosphorylation of tau and deficits in learning and memory were observed at P28 and P30. Administration of perioperative ibuprofen led to improvements in cognitive performance, reduction of systemic inflammation, and inhibiting abnormal phosphorylation of tau in the frontal cortex and hippocampus. Our findings indicate that cognitive dysfunction is correlated with elevated levels of inflammatory cytokines and tau phosphorylation. Cognitive impairment and tau phosphorylation after laparotomy can persist at least until P28. Anti-inflammatory medications have been shown to enhance cognitive function by rapidly reducing inflammation in the brain, while also impacting neurological changes. This discovery may have implications for the development of treatment strategies aimed at managing cognitive impairment in post-operative patients.