The microbiota plays a critical, weight-promoting role in diet-induced obesity (DIO), but the pathways that cause the microbiota to induce weight gain are unknown. We report that mice deficient in lymphotoxin (LT), a key molecule in gut immunity, were resistant to DIO. Ltbr−/− mice differed in microbial community composition compared to their heterozygous littermates, including an overgrowth of segmented filamentous bacteria (SFB). Furthermore, cecal transplantation conferred leanness to germ-free recipients. Housing Ltbr−/− mice with their obese siblings rescued weight gain, demonstrating the communicability of the obese phenotype. Ltbr−/− animals lacked interleukin 23 (IL-23) and IL-22 that can regulate SFB. Mice deficient in these pathways also resisted DIO, demonstrating that intact mucosal immunity guides diet-induced changes to the microbiota to enable obesity.