We aimed to investigate the association between being an immigrant and long-term prescription opioid use in Norway in 2010-2019. Nested case-control study. The cases were all persons 18 years of age or older with long-term opioid use - that is, the use of prescription opioids longer than 3 months (N=215,642). Cases were matched to four controls who filled at least one opioid prescription, but never developed long-term opioid use in the study period (N=862,568) on sex, age and year of starting long-term/short-term opioid use. Being an immigrant was defined as being born outside of Norway to two foreign-born parents and four foreign-born grandparents. Adjusting for socioeconomic variables and clinical confounders, analyses were stratified on three age groups (18-44 years, 45-67 years and ⩾68 years). For the youngest age group, being an immigrant was inversely associated with long-term opioid use (adjusted odds ratio 0.75; 95% confidence interval [0.72-0.77]) compared with being native-born people. For this age group, the odds ratio differed between people born in Africa (0.56 [0.52-0.62]), Central or South America (0.70 [0.62-0.79]), Europe outside the European Union (EU) (0.71 [0.65-0.77]), Asia including Turkey (0.80 [0.77-0.84]) and EU/European Economic Area (EEA) (0.81 [0.77-0.85]). For the middle age group, increased odds were found for immigrants versus natives (1.05 [1.02-1.08]) in particular for those born in North America (1.26 [1.13-1.40]) and the EU/EEA (1.13 [1.09-1.18]). There was no association in the oldest group. Compared with native-born people, immigrants had lower odds of long-term opioid use among younger adults, higher odds among middle-aged and similar odds among older adults.