Background The US opioid epidemic has led to similar concerns about prescribed opioids in the UK. In new users, initiation of or escalation to more potent and high dose opioids may contribute to long-term use. Additionally, physician prescribing behaviour has been described as a key driver of rising opioid prescriptions and long-term opioid use. No studies to our knowledge have investigated the extent to which regions, practices, and prescribers vary in opioid prescribing whilst accounting for case mix. This study sought to (i) describe prescribing trends between 2006 and 2017, (ii) evaluate the transition of opioid dose and potency in the first 2 years from initial prescription, (iii) quantify and identify risk factors for long-term opioid use, and (iv) quantify the variation of long-term use attributed to region, practice, and prescriber, accounting for case mix and chance variation. Methods and findings A retrospective cohort study using UK primary care electronic health records from the Clinical Practice Research Datalink was performed. Adult patients without cancer with a new prescription of an opioid were included; 1,968,742 new users of opioids were identified. Mean age was 51 ± 19 years, and 57% were female. Codeine was the most commonly prescribed opioid, with use increasing 5-fold from 2006 to 2017, reaching 2,456 prescriptions/10,000 people/year. Morphine, buprenorphine, and oxycodone prescribing rates continued to rise steadily throughout the study period. Of those who started on high dose (120–199 morphine milligram equivalents [MME]/day) or very high dose opioids (≥200 MME/day), 10.3% and 18.7% remained in the same MME/day category or higher at 2 years, respectively. Following opioid initiation, 14.6% became long-term opioid users in the first year. In the fully adjusted model, the following were associated with the highest adjusted odds ratios (aORs) for long-term use: older age (≥75 years, aOR 4.59, 95% CI 4.48–4.70, p < 0.001; 65–74 years, aOR 3.77, 95% CI 3.68–3.85, p < 0.001, compared to <35 years), social deprivation (Townsend score quintile 5/most deprived, aOR 1.56, 95% CI 1.52–1.59, p < 0.001, compared to quintile 1/least deprived), fibromyalgia (aOR 1.81, 95% CI 1.49–2.19, p < 0.001), substance abuse (aOR 1.72, 95% CI 1.65–1.79, p < 0.001), suicide/self-harm (aOR 1.56, 95% CI 1.52–1.61, p < 0.001), rheumatological conditions (aOR 1.53, 95% CI 1.48–1.58, p < 0.001), gabapentinoid use (aOR 2.52, 95% CI 2.43–2.61, p < 0.001), and MME/day at initiation (aOR 1.08, 95% CI 1.07–1.08, p < 0.001). After adjustment for case mix, 3 of the 10 UK regions (North West [16%], Yorkshire and the Humber [15%], and South West [15%]), 103 practices (25.6%), and 540 prescribers (3.5%) had a higher proportion of patients with long-term use compared to the population average. This study was limited to patients prescribed opioids in primary care and does not include opioids available over the counter or prescribed in hospitals or drug treatment centres. Conclusions Of patients commencing opioids on very high MME/day (≥200), a high proportion stayed in the same category for a subsequent 2 years. Age, deprivation, prescribing factors, comorbidities such as fibromyalgia, rheumatological conditions, recent major surgery, and history of substance abuse, alcohol abuse, and self-harm/suicide were associated with long-term opioid use. Despite adjustment for case mix, variation across regions and especially practices and prescribers in high-risk prescribing was observed. Our findings support greater calls for action for reduction in practice and prescriber variation by promoting safe practice in opioid prescribing.