BACKGROUND Opioid drug prescription (ODP) and opioid-related mortality (ORM) have increased in Spain. However, their relationship is complex, as ORM is registered without considering the type of opioid (legal/illegal). OBJECTIVE This ecological study aims to examine the correlation between ODP and ODP in Spain. METHODS Information on ODP (2000-2019) was obtained from the Spanish Medicines Agency in daily doses per 1,000 inhabitants per day (DHD) for: total ODP, total excluding those with better safety protocols (codeine and/or tramadol), and for each opioid drug separately. Rates of ORM (per 10^6 inhabitants) were calculated based on deaths registered (CIE-10) as opioid poisoning by the National Statistics Institute. The evolution of ODP and ORM was determined separately, as well as their correlations. Their temporal evolution was analyzed using cross-correlations with 24 lags and the cross-correlation function. RESULTS The rate of ORM (2000-2019) ranged between 14/10^6 and 23/10^6, with a minimum in 2006, and an increasing trend starting in 2010. The ODP ranged between 1.51 to 19.94 DHD. The rates of ORM were directly correlated with the DHD of total ODP (r=0.597;p=0.006), total without codeine and tramadol (r=0.934;p CONCLUSIONS There is a correlation between prescription of strong opioid drugs and ORM. The role of tramadol and fentanyl is especially important. Control measures should be implemented so that dispensation of these pharmaceuticals strictly follows clinical guidelines, and each patient should be frequently reevaluated.