Contextual memory formation relies on the induction of new genes in the hippocampus. A polymorphism in the promoter of the transcription factor XBP1 was identified as a risk factor for Alzheimer’s disease and bipolar disorders. XBP1 is a major regulator of the unfolded protein response (UPR), mediating adaptation to endoplasmic reticulum (ER) stress. Using a phenotypic screen, we uncovered an unexpected function of XBP1 in cognition and behavior. Mice lacking XBP1 in the nervous system showed specific impairment of contextual memory formation and long-term potentiation (LTP), whereas neuronal XBP1s overexpression improved performance in memory tasks. Gene expression analysis revealed that XBP1 regulates a group of memory-related genes, highlighting brain-derived neurotrophic factor (BDNF), a key component in memory consolidation. Overexpression of BDNF in the hippocampus reversed the XBP1-deficient phenotype. Our study revealed an unanticipated function of XBP1 in cognitive processes that is apparently unrelated to its role in ER stress.