Can mating influence cognitive functions such as learning and memory in a permanent way? We have addressed this question using a combined behavioral and in vivo imaging approach, finding that aversive long-term memory performance strongly increases in Drosophila females in response to sperm transfer following mating. A peptide in the male sperm, the sex peptide, is known to cause marked changes in female reproductive behavior, as well as other behaviors such as dietary preference. Here, we demonstrate that this sex peptide enhances memory by acting on a single pair of serotonergic brain neurons, in which activation of the sex peptide receptor stimulates the cyclic adenosine monophosphate/protein kinase A pathway. We thus reveal a strong effect of mating on memory via the neuromodulatory action of a sperm peptide on the female brain.