Background: Consistently high rates of premature mortality have been reported in individuals who receive community sentences. However, few studies have explored potential modifiable risk factors for these rates, particularly mental health. We examined the association of substance use and other psychiatric disorders with all-cause and external-cause mortality in individuals convicted of a criminal offence and given a community sentence. Methods: We did a longitudinal cohort study of 109,751 individuals given community sentences in Sweden using population-based registers. We calculated mortality rates for all-cause and external-cause mortality, hazard ratios for the association between psychiatric disorders and mortality, and population attributable fractions to quantify the contribution of psychiatric disorders to mortality risk. Findings: During the follow-up, 5749 (5.2%) individuals died, including 2709 (2.5%) from external causes. Individuals with pre-existing substance use and other psychiatric disorders had an increased mortality risk from any cause (aHR = 2.28 [95% CI 2.15–2.42]) and from external causes (3.11 [2.85–3.40]) compared to individuals without known psychiatric or substance use disorders. Suicide was the most common cause of death in younger persons. Interpretation: In individuals given community sentences, substance use and other psychiatric disorders were associated with an increased risk of premature death with suicide being the leading cause of death. Community supervision represents an opportunity to provide sentenced individuals with access to evidence-based treatment targeting substance misuse and psychiatric disorders to prevent potentially preventable deaths. Funding: Wellcome Trust.