Importance: Expanding Medicaid eligibility could affect prescriptions of buprenorphine with naloxone, an established treatment for opioid use disorder, and opioid pain relievers (OPRs). Objective: To examine changes in prescriptions of buprenorphine with naloxone and OPRs after the US Affordable Care Act Medicaid expansion. Design, Setting, and Participants: In this cohort study, longitudinal, patient-level, retail pharmacy claims were extracted from IQVIA real-world data from an anonymized, longitudinal, prescription database. The sample included 11.9 million individuals who filled 2 or more prescriptions for a prescription opioid during at least 1 year between January 1, 2010, and December 31, 2015, from California, Maryland, and Washington (expansion states) and Florida and Georgia (nonexpansion states). Data analysis was conducted from August 1, 2017, to May 31, 2018. Data were aggregated to county-year observations (N = 2082) and linked to county-level covariates. For each outcome, a difference-in-differences regression model was estimated comparing changes before and after expansion in expansion vs nonexpansion counties. Models were adjusted for county demographics, uninsured rate, and overdose mortality in the baseline year (2010). Exposures: Presence of Medicaid expansion in the year. Main Outcomes and Measures: For buprenorphine with naloxone and OPRs, rates per 100 000 county residents were calculated separately for any prescriptions overall and by different payment sources. Mean days of medication per county among people filling prescriptions for these agents were also determined. Results: The study sample included 11.9 million individuals (expansion states: 40.9% men; mean [SD] age, 44.1 [13.8] years; nonexpansion states: 41.0% men; mean [SD] age, 43.7 [13.7] years). In expansion counties, 68.8 individuals per 100 000 county residents filled buprenorphine with naloxone and 5298.3 filled OPR prescriptions in 2010. After expansion, buprenorphine with naloxone fills per 100 000 county residents increased significantly in expansion relative to nonexpansion counties (8.7; 95% CI, 1.7 to 15.7). Opioid pain reliever fills per 100 000 county residents did not significantly change in expansion counties relative to nonexpansion counties (327.4; 95% CI -202.5 to 857.4). The rate of OPRs per 100 000 county residents paid for by Medicaid significantly increased (374.0; 95% CI, 258.3 to 489.7). There were no significant changes in days per 100 000 county residents of either medication after expansion. Conclusions and Relevance: Medicaid expansion significantly increased buprenorphine with naloxone prescriptions per 100 000 county residents in expansion counties, suggesting that expansion improved access to opioid use disorder treatment. Expansion did not significantly increase the overall rate per 100 000 county residents of OPR prescriptions, but increased the population with OPRs paid for by Medicaid. This finding therefore suggests the growing importance of Medicaid in pain management and addiction prevention.