Background Prescription-type opioid use disorder (POUD) is often accompanied by comorbid anxiety, yet the impact of anxiety on retention in opioid agonist therapy (OAT) is unclear. Therefore, this study investigated whether baseline anxiety severity affects retention in OAT and whether this effect differs by OAT type (methadone maintenance therapy (MMT) vs. buprenorphine/naloxone (BNX)). Methods This secondary analysis used data from a pan-Canadian randomized trial comparing flexible take-home dosing BNX and standard supervised MMT for 24 weeks. The study included 268 adults with POUD. Baseline anxiety was assessed using the Beck Anxiety Inventory (BAI), with BAI ≥ 16 indicating moderate-to-severe anxiety. The primary outcomes were retention in assigned and any OAT at week 24. In addition, the impact of anxiety severity on retention was examined, and assigned OAT was considered an effect modifier. Results Of the participants, 176 (65%) reported moderate-to-severe baseline anxiety. In adjusted analyses, there was no significant difference in retention between those with BAI ≥ 16 and those with BAI < 16 assigned (29% vs. 28%; odds ratio (OR) = 2.03, 95% confidence interval (CI) = 0.94–4.40; P = 0.07) or any OAT (35% vs. 34%; OR = 1.57, 95% CI = 0.77–3.21; P = 0.21). In addition, there was no significant effect modification by OAT type for retention in assigned ( P = 0.41) or any OAT ( P = 0.71). In adjusted analyses, greater retention in treatment was associated with BNX (vs. MMT), male gender identity (vs. female, transgender, or other), enrolment in the Quebec study site (vs. other sites), and absence of a positive urine drug screen for stimulants at baseline. Conclusions Baseline anxiety severity did not significantly impact retention in OAT for adults with POUD, and there was no significant effect modification by OAT type. However, the overall retention rates were low, highlighting the need to develop new strategies to minimize the risk of attrition from treatment. Clinical Trial Registration This study was registered in ClinicalTrials.gov (NCT03033732).