The past decade saw rapid declines in opioids dispensed to patients with active cancer, with a concurrent increase in marijuana use among cancer survivors possibly associated with state medical marijuana legalization. To assess the associations between medical marijuana legalization and opioid-related and pain-related outcomes for adult patients receiving cancer treatment. This cross-sectional study used 2012 to 2017 national commercial claims data and a difference-in-differences design to estimate the associations of interest for patients residing in 34 states without medical marijuana legalization by January 1, 2012. Secondary analysis differentiated between medical marijuana legalization with and without legal allowances for retail dispensaries. Data analysis was conducted between December 2021 and August 2022. Study samples included privately insured patients aged 18 to 64 years who received anticancer treatment during the 6 months after a new breast (in women), colorectal, or lung cancer diagnosis. State medical marijuana legalization that took effect between 2012 and 2017. Having 1 or more days of opioids, 1 or more days of long-acting opioids, total morphine milligram equivalents of any opioid dispensed to patients with 1 or more opioid days, and 1 or more pain-related emergency department visits or hospitalizations (hereafter, hospital events) during the 6 months after a new cancer diagnosis. Interaction terms were included between each policy indicator and an indicator of recent opioids, defined as having 1 or more opioid prescriptions during the 12 months before the new cancer diagnosis. Logistic models were estimated for dichotomous outcomes, and generalized linear models were estimated for morphine milligram equivalents. The analysis included 38 189 patients newly diagnosed with breast cancer (38 189 women [100%]), 12 816 with colorectal cancer (7100 men [55.4%]), and 7190 with lung cancer (3674 women [51.1%]). Medical marijuana legalization was associated with a reduction in the rate of 1 or more opioid days from 90.1% to 84.4% (difference, 5.6 [95% CI, 2.2-9.0] percentage points; P = .001) among patients with breast cancer with recent opioids, from 89.4% to 84.4% (difference, 4.9 [95% CI, 0.5-9.4] percentage points; P = .03) among patients with colorectal cancer with recent opioids, and from 33.8% to 27.2% (difference, 6.5 [95% CI, 1.2-11.9] percentage points; P = .02) among patients with lung cancer without recent opioids. Medical marijuana legalization was associated with a reduction in the rate of 1 or more pain-related hospital events from 19.3% to 13.0% (difference, 6.3 [95% CI, 0.7-12.0] percentage points; P = .03) among patients with lung cancer with recent opioids. Findings of this cross-sectional study suggest that medical marijuana legalization implemented from 2012 to 2017 was associated with a lower rate of opioid dispensing and pain-related hospital events among some adults receiving treatment for newly diagnosed cancer. The nature of these associations and their implications for patient safety and quality of life need to be further investigated.