To combat the nationwide opioid epidemic, many states have implemented policies that require prescribers to check a patient's prescription history with Prescription Drug Monitoring Programs (PDMPs) prior to initiating or refilling opioid prescriptions. Using a difference‐in‐differences approach, we show that after states mandated PDMP use, opioid prescriptions decreased by 6.1% as intended. However, PDMP mandates had the unintended effect of driving existing opioid users towards more lethal illicit substitutes such as heroin. We found that reductions in prescription rates were accompanied by unprecedented rises in heroin overdose deaths: there were 6.37 more heroin‐related deaths per million population per year—a 50.1% increase—following PDMP mandates. Although stronger PDMP mandates (e.g., based on comprehensiveness, legal enforcement, integration with other health records, and interstate information sharing) reduced opioid prescriptions, we also find that stronger mandates inadvertently increased heroin overdose deaths. Additional analyses show that the substitution effect was not statistically significant among states with lower preexisting levels of pain reliever dependence, lower heroin availability, and greater access to substance abuse treatment. These findings point to an important policy implication: supply‐side restrictions such as mandated PDMP need to account for possible demand‐side substitution effects.