The ketogenic diet (KD) is used to treat refractory epilepsy, but the mechanisms underlying its neuroprotective effects remain unclear. Here, we show that the gut microbiota is altered by the KD and required for protection against acute electrically induced seizures and spontaneous tonic-clonic seizures in two mouse models. Mice treated with antibiotics or reared germ free are resistant to KD-mediated seizure protection. Enrichment of, and gnotobiotic co-colonization with, KD-associated Akkermansia and Parabacteroides restores seizure protection. Moreover, transplantation of the KD gut microbiota and treatment with Akkermansia and Parabacteroides each confer seizure protection to mice fed a control diet. Alterations in colonic lumenal, serum, and hippocampal metabolomic profiles correlate with seizure protection, including reductions in systemic gamma-glutamylated amino acids and elevated hippocampal GABA/glutamate levels. Bacterial cross-feeding decreases gamma-glutamyltranspeptidase activity, and inhibiting gamma-glutamylation promotes seizure protection in vivo. Overall, this study reveals that the gut microbiota modulates host metabolism and seizure susceptibility in mice.