To compare opioid use in patients with obesity treated with bariatric surgery versus adults with obesity who underwent intensive lifestyle modification. Previous studies of opioid use after bariatric surgery have been limited by small sample sizes, short follow-up, and lack of control groups. Nationwide matched cohort study including individuals from the Scandinavian Obesity Surgery Registry and the Itrim health database with individuals undergoing structured intensive lifestyle modification, between August 1, 2007 and September 30, 2015. Participants were matched on Body Mass Index, age, sex, education, previous opioid use, diabetes, cardiovascular disease, and psychiatric status (n = 30,359:21,356). Dispensed opioids were retrieved from the Swedish Prescribed Drug Register from 2 years before to up to 8 years after intervention. During the 2-year period before treatment, prevalence of individuals receiving ≥1 opioid prescription was identical in the surgery and lifestyle group. At 3 years, the prevalence of opioid prescriptions was 14.7% versus 8.9% in the surgery and lifestyle groups (mean difference 5.9%, 95% confidence interval 5.3-6.4) and at 8 years 16.9% versus 9.0% (7.9%, 6.8-9.0). The difference in mean daily dose also increased over time and was 3.55 mg in the surgery group versus 1.17 mg in the lifestyle group at 8 years (mean difference [adjusted for baseline dose] 2.30 mg, 95% confidence interval 1.61-2.98). Bariatric surgery was associated with a higher proportion of opioid users and larger total opioid dose, compared to actively treated obese individuals. These trends were especially evident in patients who received additional surgery during follow-up.