Significance: In humans, obesity impairs cognition and produces atrophy of brain regions associated with learning and memory, but few studies have investigated the underlying cellular mechanisms. We used a diet-induced model of obesity in rats to study excessive weight gain and found that early stage obesity, before the onset of diabetes or metabolic syndrome, produced deficits on cognitive tasks that require the prefrontal cortex. Impaired cognition was associated with synapse loss, including reduced numbers of dendritic spines and expression of synaptic proteins, as well as structural alterations in the brain’s immune cells, the microglia. These results strongly suggest that obesity must be considered as a contributing factor to brain dysfunction, with implications for its increasing frequency in contemporary western society.