Perioperative neurocognitive disorder may develop in vulnerable patients following major operation. While neuroinflammation is linked to the cognitive effects of surgery, how surgery and immune signaling modulate neuronal circuits, leading to learning and memory impairment remains unknown. Using in vivo two‐photon microscopy, Ca2+ activity and postsynaptic dendritic spines of layer 5 pyramidal neurons in the primary motor cortex of a mouse model of thoracic surgery are imaged. It is found that surgery causes neuronal hypoactivity, impairments in learning‐dependent dendritic spine formation, and deficits in multiple learning tasks. These neuronal and synaptic alterations in the cortex are mediated by peripheral monocytes through the NLRP3 inflammasome‐dependent IL‐1β production. Depleting peripheral monocytes or inactivating NLRP3 inflammasomes before surgery reduces levels of IL‐1β and ameliorates neuronal and behavioral deficits in mice. Furthermore, adoptive transfer of IL‐1β‐producing myeloid cells from mice undertaking thoracic surgery is sufficient to induce neuronal and behavioral deficits in naïve mice. Together, these findings suggest that surgery leads to excessive NLRP3 activation in monocytes and elevated IL‐1β signaling, which in turn causes neuronal hypoactivity and perioperative neurocognitive disorder.