The gut microbiota is essential for the normal function of the gut immune system, and microbiota alterations are associated with autoimmune disorders. However, how the gut microbiota prevents autoimmunity in distant organs remains poorly defined. Here we reveal that gut microbiota conditioned innate lymphoid cells (ILCs) induce the expression of mouse β-defensin 14 (mBD14) by pancreatic endocrine cells, preventing autoimmune diabetes in the non-obese diabetic (NOD) mice. MBD14 stimulates, via Toll-like receptor 2, interleukin-4 (IL-4)-secreting B cells that induce regulatory macrophages, which in turn induce protective regulatory T cells. The gut microbiota-derived molecules, aryl hydrocarbon receptor (AHR) ligands and butyrate, promote IL-22 secretion by pancreatic ILCs, which induce expression of mBD14 by endocrine cells. Dysbiotic microbiota and low-affinity AHR allele explain the defective pancreatic expression of mBD14 observed in NOD mice. Our study reveals a yet unidentified crosstalk between ILCs and endocrine cells in the pancreas that is essential for the prevention of autoimmune diabetes development.