Type 1 diabetes (T1D) is an autoimmune disease in which insulin-producing pancreatic β-cells are destroyed. Intestinal helminths can cause asymptomatic chronic and immunosuppressive infections and suppress disease in rodent models of T1D. However, the underlying regulatory mechanisms for this protection are unclear. Here, we report that CD8+ regulatory T (Treg) cells prevent the onset of streptozotocin -induced diabetes by a rodent intestinal nematode. Trehalose derived from nematodes affects the intestinal microbiota and increases the abundance of Ruminococcus spp., resulting in the induction of CD8+ Treg cells. Furthermore, trehalose has therapeutic effects on both streptozotocin-induced diabetes and in the NOD mouse model of T1D. In addition, compared with healthy volunteers, patients with T1D have fewer CD8+ Treg cells, and the abundance of intestinal Ruminococcus positively correlates with the number of CD8+ Treg cells in humans.