Persons dependent on opioids like heroin, morphine, or codeine have a high risk of relapse, overdose and overdose death. This risk is elevated even further following discharge from treatment or correctional institutions where patients have been detoxified. At the moment, state-of-the-art treatment is based on maintaining the dependence on opioids by daily intake of opioid medications like methadone or buprenorphine. Recently, a medication containing the blocking agent naltrexone was approved in the US; this does not maintain dependence but instead blocks heroin and other opioids for 28 days after intramuscular administration. This study will conduct a 12-week randomized comparison of naltrexone intramuscular suspension (XL-NTX) with daily buprenorphine-naloxone in OMT. Medication will start preceding discharge from a treatment or correctional facility to participating catchment regions in Norway. The main hypotheses are that XL-NTX will do equally well as - or better than - OMT on the proportion of biological samples negative for opioids, retention, self-reported use of alcohol and illicit drugs. Following the 12-week randomized period, there will be a 36-week period where participants can receive the study medication of their choice. After the end of the study, data from national registry databases can be collected for a further 12 months on outcomes such as recidivism, mortality and morbidity.