Background Ecological research suggests that increased access to cannabis may facilitate reductions in opioid use and harms, and medical cannabis patients describe the substitution of opioids with cannabis for pain management. However, there is a lack of research using individual-level data to explore this question. We aimed to investigate the longitudinal association between frequency of cannabis use and illicit opioid use among people who use drugs (PWUD) experiencing chronic pain. Methods and findings This study included data from people in 2 prospective cohorts of PWUD in Vancouver, Canada, who reported major or persistent pain from June 1, 2014, to December 1, 2017 (n = 1,152). We used descriptive statistics to examine reasons for cannabis use and a multivariable generalized linear mixed-effects model to estimate the relationship between daily (once or more per day) cannabis use and daily illicit opioid use. There were 424 (36.8%) women in the study, and the median age at baseline was 49.3 years (IQR 42.3–54.9). In total, 455 (40%) reported daily illicit opioid use, and 410 (36%) reported daily cannabis use during at least one 6-month follow-up period. The most commonly reported therapeutic reasons for cannabis use were pain (36%), sleep (35%), stress (31%), and nausea (30%). After adjusting for demographic characteristics, substance use, and health-related factors, daily cannabis use was associated with significantly lower odds of daily illicit opioid use (adjusted odds ratio 0.50, 95% CI 0.34–0.74, p < 0.001). Limitations of the study included self-reported measures of substance use and chronic pain, and a lack of data for cannabis preparations, dosages, and modes of administration. Conclusions We observed an independent negative association between frequent cannabis use and frequent illicit opioid use among PWUD with chronic pain. These findings provide longitudinal observational evidence that cannabis may serve as an adjunct to or substitute for illicit opioid use among PWUD with chronic pain., M-J Milloy and colleagues investigate use of cannabis and illicit opioids among people who use drugs reporting chronic pain., Author summary Why was this study done? High numbers of people who use (illicit) drugs (PWUD) experience chronic pain, and previous research shows that illicit use of opioids (e.g., heroin use, non-prescribed use of painkillers) is a common pain management strategy in this population. Previous research has suggested that some patients might substitute opioids (i.e., prescription painkillers) with cannabis (i.e., marijuana) to treat pain. Research into cannabis as a potential substitute for illicit opioids among PWUD is needed given the high risk of opioid overdose in this population. We conducted this study to understand if cannabis use is related to illicit opioid use among PWUD who report living with chronic pain in Vancouver, Canada, where cannabis is abundant and the rate of opioid overdose is at an all-time high. What did the researchers do and find? Using data from 2 large studies of PWUD in Vancouver, Canada, we analyzed information from 1,152 PWUD who were interviewed at least once and reported chronic pain at some point between June 2014 and December 2017. We used statistical modelling to estimate the odds of daily opioid use for (1) daily and (2) occasional users of cannabis relative to non-users of cannabis, holding other factors (e.g., sex, race, age, use of other drugs, pain severity) equal. For participants who reported cannabis use, we also analyzed their responses to a question about why they were using cannabis (e.g., for intoxication, for pain relief) We found that people who used cannabis every day had about 50% lower odds of using illicit opioids every day compared to cannabis non-users. People who reported occasional use of cannabis were not more or less likely than non-users to use illicit opioids on a daily basis. Daily cannabis users were more likely than occasional cannabis users to report a number of therapeutic uses of cannabis including for pain, nausea, and sleep. What do these findings mean? Although more experimental research (e.g., randomized controlled trial of cannabis coupled with low-dose opioids to treat chronic pain among PWUD) is needed, these findings suggest that some PWUD with pain might be using cannabis as a strategy to alleviate pain and/or reduce opioid use.