ImportanceCannabis use is increasing worldwide and is suspected to be associated with increased risk of psychiatric disorders; however, the association with affective disorders has been insufficiently studied.ObjectiveTo examine whether cannabis use disorder (CUD) is associated with an increased risk of psychotic and nonpsychotic unipolar depression and bipolar disorder and to compare associations of CUD with psychotic and nonpsychotic subtypes of these diagnoses.Design, Setting, and ParticipantsThis prospective, population-based cohort study using Danish nationwide registers included all individuals born in Denmark before December 31, 2005, who were alive, aged at least 16 years, and living in Denmark between January 1, 1995, and December 31, 2021.ExposureRegister-based diagnosis of CUD.Main Outcome and MeasuresThe main outcome was register-based diagnosis of psychotic or nonpsychotic unipolar depression or bipolar disorder. Associations between CUD and subsequent affective disorders were estimated as hazard ratios (HRs) using Cox proportional hazards regression with time-varying information on CUD, adjusting for sex; alcohol use disorder; substance use disorder; having been born in Denmark; calendar year; parental educational level (highest attained); parental cannabis, alcohol, or substance use disorders; and parental affective disorders.ResultsA total of 6 651 765 individuals (50.3% female) were followed up for 119 526 786 person-years. Cannabis use disorder was associated with an increased risk of unipolar depression (HR, 1.84; 95% CI, 1.78-1.90), psychotic unipolar depression (HR, 1.97; 95% CI, 1.73-2.25), and nonpsychotic unipolar depression (HR, 1.83; 95% CI, 1.77-1.89). Cannabis use was associated with an increased risk of bipolar disorder in men (HR, 2.96; 95% CI, 2.73-3.21) and women (HR, 2.54; 95% CI, 2.31-2.80), psychotic bipolar disorder (HR, 4.05; 95% CI, 3.52-4.65), and nonpsychotic bipolar disorder in men (HR, 2.96; 95% CI, 2.73-3.21) and women (HR, 2.60; 95% CI, 2.36-2.85). Cannabis use disorder was associated with higher risk for psychotic than nonpsychotic subtypes of bipolar disorder (relative HR, 1.48; 95% CI, 1.21-1.81) but not unipolar depression (relative HR, 1.08; 95% CI, 0.92-1.27).Conclusions and RelevanceThis population-based cohort study found that CUD was associated with an increased risk of psychotic and nonpsychotic bipolar disorder and unipolar depression. These findings may inform policies regarding the legal status and control of cannabis use.