I'll break it down a little for you.
Pain Med A is effective as a pain reliever. Over time it is realized that Pain Med A is highly addictive and that many who used the medication as it was intended became addicted and that the addiction even led to many unintended deaths.
Pain Med B was discovered to fight pain equally well but without the addictive properties.
Pain Med A was removed from the market and replaced with Pain Med B. People in legitimate need of pain medication were still able to get the medication needed, but now with far less risk of becoming addicted.
People already addicted to Pain Med A were bummed and looked for illegal sources of Pain Med A. Many (but not all) found those illegal sources. Over time, far fewer people became addicted to Pain Med A as otherwise would have been the case.
Innocent lives were saved and no one lost their ability to get effective pain medication.