Impaired learning and cognitive function often occurs during systemic infection or inflammation. Although activation of the innate immune system has been linked to the behavioral and cognitive effects that are associated with infection, the underlying mechanisms remain poorly understood. Here we mimicked viral immune activation with poly(I:C), a synthetic analog of double-stranded RNA, and longitudinally imaged postsynaptic dendritic spines of layer V pyramidal neurons in the mouse primary motor cortex using two-photon microscopy. We found that peripheral immune activation caused dendritic spine loss, impairments in learning-dependent dendritic spine formation and deficits in multiple learning tasks in mice. These observed synaptic alterations in the cortex were mediated by peripheral-monocyte-derived cells and did not require microglial function in the central nervous system. Furthermore, activation of CX3CR1highLy6Clow monocytes impaired motor learning and learning-related dendritic spine plasticity through tumor necrosis factor (TNF)-α-dependent mechanisms. Taken together, our results highlight CX3CR1high monocytes and TNF-α as potential therapeutic targets for preventing infection-induced cognitive dysfunction.