Homelessness is associated with adverse health and social outcomes. People experiencing homelessness have been found to have a high risk of violent crime victimisation as well as high prevalence of psychiatric disorders. It is poorly understood whether experiencing homelessness is associated with additional risks of violent offending and whether psychiatric disorders contribute to these risks. We examined the association between homelessness, psychiatric disorders, and first violence offence leading to conviction. We did a nationwide, register-based cohort study of all Danish residents who were alive at least 1 day during the study period, born between Jan 1, 1980, and Dec 31, 2006, and aged 15 years or older retrieved from the Danish Civil Registration System, which was linked to registers with information on homelessness, health care, and criminality. The exposure was any experience of homelessness, which was defined as having at least one contact with a homeless shelter during the study period. The outcome was first violent offence leading to a conviction. We calculated incidence rates per 10 000 person-years, incidence rate ratios (IRRs) using Poisson regression analysis, and probability of conviction of a violent offence using an Aalen-Johansen estimator. Analyses were stratified by sex and adjusted for calendar year of the study period, age, other sociodemographic factors, and psychiatric disorders. The study cohort included 1 786 433 Danish residents aged 15-42 years living in Denmark at some point from Jan 1, 2001, to Dec 31, 2021, contributing to 21 336 322 person-years at risk, of whom 57 084 (3·2%) individuals had their first violent offence leading to conviction during follow-up. 10 years after their first contact with a homeless shelter, 22·9% (95% CI 21·6-24·2) of men and 7·7% (6·8-8·7) of women had committed at least one violent crime leading to conviction. The fully adjusted IRRs of a violent offence leading to conviction were 4·8 (4·5-5·1) in men and 6·3 (5·6-7·2) in women experiencing homelessness compared with individuals who had not experienced homelessness. The IRR for a violent offence leading to conviction was highest in individuals experiencing homelessness and having co-occurring psychiatric disorders compared with those not experiencing homelessness and without co-occurring psychiatric disorders, especially drug use disorders (IRR in those experiencing homelessness and having a drug use disorder: 15·3 [14·1-16·7] in men and 40·1 [33·9-47·5] in women compared with individuals not experiencing homelessness and having no drug use disorder). Individuals experiencing homelessness had higher risks of a violent offence leading to conviction than those who had not experienced homelessness. In addition to preventing homelessness, public health and policy should consider how to reduce the risk of adverse outcomes in people experiencing homelessness. Lundbeck Foundation.