Infection-related diabetes can arise as a result of virus-associated β-cell destruction. Clinical data suggest that the severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), causing the coronavirus disease 2019 (COVID-19), impairs glucose homoeostasis, but experimental evidence that SARS-CoV-2 can infect pancreatic tissue has been lacking. In the present study, we show that SARS-CoV-2 infects cells of the human exocrine and endocrine pancreas ex vivo and in vivo. We demonstrate that human β-cells express viral entry proteins, and SARS-CoV-2 infects and replicates in cultured human islets. Infection is associated with morphological, transcriptional and functional changes, including reduced numbers of insulin-secretory granules in β-cells and impaired glucose-stimulated insulin secretion. In COVID-19 full-body postmortem examinations, we detected SARS-CoV-2 nucleocapsid protein in pancreatic exocrine cells, and in cells that stain positive for the β-cell marker NKX6.1 and are in close proximity to the islets of Langerhans in all four patients investigated. Our data identify the human pancreas as a target of SARS-CoV-2 infection and suggest that β-cell infection could contribute to the metabolic dysregulation observed in patients with COVID-19.