The risk of death by suicide in individuals with obsessive-compulsive disorder (OCD) is largely unknown. Previous studies have been small and methodologically flawed. We analyzed data from the Swedish national registers to estimate the risk of suicide in OCD and identify the risk and protective factors associated with suicidal behavior in this group. We used a matched case-cohort design to estimate the risk of deaths by suicide and attempted suicide in individuals diagnosed with OCD, compared with matched general population controls (1:10). Cox regression models were used to study predictors of suicidal behavior. We identified 36 788 OCD patients in the Swedish National Patient Register between 1969 and 2013. Of these, 545 had died by suicide and 4297 had attempted suicide. In unadjusted models, individuals with OCD had an increased risk of both dying by suicide (odds ratio (OR) = 9.83 (95% confidence interval (CI), 8.72–11.08)) and attempting suicide (OR = 5.45 (95% CI, 5.24–5.67)), compared with matched controls. After adjusting for psychiatric comorbidities, the risk was reduced but remained substantial for both death by suicide and attempted suicide. Within the OCD cohort, a previous suicide attempt was the strongest predictor of death by suicide. Having a comorbid personality or substance use disorder also increased the risk of suicide. Being a woman, higher parental education and having a comorbid anxiety disorder were protective factors. We conclude that patients with OCD are at a substantial risk of suicide. Importantly, this risk remains substantial after adjusting for psychiatric comorbidities. Suicide risk should be carefully monitored in patients with OCD.