A diet rich in salt is linked to an increased risk of cerebrovascular diseases and dementia, but it remains unclear how dietary salt harms the brain. We report that, in mice, excess dietary salt suppresses resting cerebral blood flow and endothelial function, leading to cognitive impairment. The effect depends on expansion of TH17 cells in the small intestine, resulting in a marked increase in plasma interleukin-17 (IL-17). Circulating IL-17, in turn, promotes endothelial dysfunction and cognitive impairment by the Rho kinase-dependent inhibitory phosphorylation of endothelial nitric oxide synthase and reduced nitric oxide production in cerebral endothelial cells. The findings reveal a new gut-brain axis linking dietary habits to cognitive impairment through a gut-initiated adaptive immune response compromising brain function via circulating IL-17. Thus, the TH17 cell-IL-17 pathway is a putative target to counter the deleterious brain effects induced by dietary salt and other diseases associated with TH17 polarization.