Epidemiological evidence indicates that vitamin D is involved in defense against diabetes; however, the precise underlying mechanism remains to be elucidated. In the present study, the effect of vitamin D on the pathogenesis of diabetes was investigated, with an emphasis on its direct effect on pancreatic β‑cells. A streptozotocin (STZ)‑induced type 1 diabetes mellitus (T1DM) mouse model and MIN6 mouse insulinoma β‑cells were subjected to vitamin D treatment. Histopathological analysis of pancreatic islets was performed to investigate insulitis, and reverse transcription-quantitative polymerase chain reaction and western blotting were used to determine the mRNA and protein expression levels of markers of autophagy [microtubule-associated protein 1A/1B‑light chain 3 (LC3) and Beclin 1] and regulation of apoptosis [B-cell lymphoma 2 (Bcl-2)]. Apoptosis of MIN6 cells was examined by flow cytometry following annexin V/propidium iodide labeling. The secretion of insulin was measured by ELISA. The results revealed that vitamin D reduced the incidence of T1DM, enhanced insulin secretion and relieved pancreatic inflammation in STZ‑treated mice. Furthermore, vitamin D increased the mRNA expression levels of LC3 and Beclin 1, and increased Bcl‑2 protein expression levels in STZ‑treated MIN6 cells, while decreasing the apoptosis rate. The results of the present study demonstrated, for the first time to the best of our knowledge, that vitamin D induces autophagy and suppresses apoptosis of pancreatic β‑cells, as well as preventing insulitis. These findings regarding vitamin D provide insights into its involvement in diabetes, and suggest a potential novel strategy for the treatment of diabetes via agents enhancing autophagy in pancreatic β-cells.