Alterations in gut microbiota composition are associated with metabolic syndrome and chronic inflammatory diseases such as inflammatory bowel disease. One feature of inflammation-associated gut microbiotas is enrichment of motile bacteria, which can facilitate microbiota encroachment into the mucosa and activate pro-inflammatory gene expression. Here, we set out to investigate whether elicitation of mucosal anti-flagellin antibodies by direct administration of purified flagellin might serve as a general vaccine against subsequent development of chronic gut inflammation. We show, in mice, that repeated injection of flagellin elicits increases in fecal anti-flagellin IgA and alterations in microbiota composition, reduces fecal flagellin concentration, prevents microbiota encroachment, protects against IL-10 deficiency-induced colitis, and ameliorates diet-induced obesity. Flagellin's impact on the microbiota is B-lymphocyte dependent and, in humans, obese subjects exhibit increased levels of fecal flagellin and reduced levels of fecal flagellin-specific IgA, relative to normal weight subjects. Thus, administration of flagellin, and perhaps other pathobiont antigens, may confer some protection against chronic inflammatory diseases.