The notion of “immune privilege” of the brain has been revised to accommodate its infiltration, at steady state, by immune cells that participate in normal neurophysiology. However, the immune mechanisms that regulate learning and memory remain poorly understood. Here, we show that noninflammatory interleukin-17 (IL-17) derived from a previously unknown fetal-derived meningeal-resident γδ T cell subset promotes cognition. When tested in classical spatial learning paradigms, mice lacking γδ T cells or IL-17 displayed deficient short-term memory while retaining long-term memory. The plasticity of glutamatergic synapses was reduced in the absence of IL-17, resulting in impaired long-term potentiation in the hippocampus. Conversely, IL-17 enhanced glial cell production of brain-derived neurotropic factor, whose exogenous provision rescued the synaptic and behavioral phenotypes of IL-17-deficient animals. Together, our work provides previously unknown clues on the mechanisms that regulate short-term versus long-term memory and on the evolutionary and functional link between the immune and nervous systems.