Maternal diabetes has been suggested as a risk factor for attention-deficit/hyperactivity disorder and autism in offspring, but evidence on its association with the full spectrum of psychiatric disorders remains lacking. To investigate the associations between maternal diabetes diagnosed before or during pregnancy and 10 types of psychiatric disorders in offspring during the first 4 decades of life. This population-based cohort study used data from several Danish nationwide medical and administrative registries in Denmark on all 2 413 335 live births from 1978 to 2016. Data were analyzed between October 1, 2019, and July 15, 2021. Any maternal diabetes diagnosis during pregnancy (56 206 offspring [2.3%]) and 3 diabetes subtypes (pregestational type 1 diabetes, 22 614 offspring [1.0%]; pregestational type 2 diabetes, 6713 offspring [0.3%]; and gestational diabetes, 26 879 offspring [1.1%]). Outcomes included 10 types of psychiatric disorders: any psychiatric disorder, substance use disorders, schizophrenia, mood disorders, anxiety disorders, eating disorders, personality disorders, intellectual disorders, developmental disorders, and behavioral disorders. Hazard ratios (HRs) and 95% CIs were computed using Cox proportional hazards regression models. Covariates included maternal and paternal history of any psychiatric disorder, offspring sex, calendar period of birth, singleton status, and several maternal characteristics during pregnancy (ie, age, parity, educational level, smoking, cohabitation, residence, and body mass index). Sibship design and competing risk analyses were also conducted. A total of 2 413 335 individuals (1 239 148 male participants [51%]; age range, 1-39 years; median age, 19.0 years [IQR, 5.8-20.8 years]) were included in this study. During the 39-year follow-up time, 151 208 offspring (6.4%) received a diagnosis of a psychiatric disorder. Offspring born to mothers with any diabetes diagnosis during pregnancy were at increased risk of developing any psychiatric disorder (HR, 1.15; 95% CI, 1.10-1.20), schizophrenia (HR, 1.55; 95% CI, 1.15-2.08), anxiety disorders (HR, 1.22; 95% CI, 1.09-1.36), intellectual disabilities (HR, 1.29; 95% CI, 1.11-1.50), developmental disorders (HR, 1.16; 95% CI, 1.03-1.30), and behavioral disorders (HR, 1.17; 95% CI, 1.08-1.27) compared with offspring born to mothers without a diabetes diagnosis during pregnancy. No association was observed for substance use disorders, mood disorders, eating disorders, and personality disorders. This study shows a pattern that suggests that prenatal exposure to maternal diabetes during pregnancy was associated with increased risk of psychiatric disorders overall and most specific psychiatric disorders in offspring in their first 4 decades of life.