Cortical pathology contributes to chronic cognitive impairment of patients suffering from the neuroinflammatory disease multiple sclerosis (MS). How such gray matter inflammation affects neuronal structure and function is not well understood. In the present study, we use functional and structural in vivo imaging in a mouse model of cortical MS to demonstrate that bouts of cortical inflammation disrupt cortical circuit activity coincident with a widespread, but transient, loss of dendritic spines. Spines destined for removal show local calcium accumulations and are subsequently removed by invading macrophages or activated microglia. Targeting phagocyte activation with a new antagonist of the colony-stimulating factor 1 receptor prevents cortical synapse loss. Overall, our study identifies synapse loss as a key pathological feature of inflammatory gray matter lesions that is amenable to immunomodulatory therapy.