The US has always been ahead of much of the world in drug overdose deaths — for a variety of reasons. For one, Americans are relatively wealthy, so they can afford to buy drugs. But there also appear to be cultural and socioeconomic factors at play, driving a broader increase in “deaths of despair” — such as suicides, alcohol, and drug overdose deaths — in recent years. (If you ask experts what these factors could be, you can expect them to name, well, basically everything — a weak social safety net in the US compared with other developed countries, poor access to health care in general, subpar mental health care and addiction services, manufacturing jobs moving out of the country, cuts to local government services like parks and recreation, individuals losing a sense of spiritual or existential meaning, and so on.)

But recently, America has gotten much worse due to its massive opioid epidemic, which has contributed to a huge spike in drug overdose deaths over the past couple of decades. In 1999, fewer than 17,000 people died from drug overdoses. In 2015, that grew to more than 52,000.

This is, for now, largely an American problem. After pharmaceutical companies heavily marketed their opioids in the US, and doctors followed through with massive numbers of prescriptions, America became the world’s leader in consuming opioids — with UN dataputting the US at the top of opioid consumption. (Notably, other developed countries have tighter restrictions on pharmaceutical marketing than the US does.)

These two charts, then, are closely tied: As America consumed more opioids, its drug overdose deaths climbed. So it began to dominate the world on a very grim statistic.

This latest drug epidemic, however, is not solely about illegal drugs. It began, in fact, with a legal drug.

Back in the 1990s, doctors were persuaded to treat pain as a serious medical issue. There’s a good reason for that: About 100 million US adults suffer from chronic pain, according to a 2011 report from the Institute of Medicine.

Pharmaceutical companies took advantage of this concern. Through a big marketing campaign, they got doctors to prescribe products like OxyContin and Percocet in droves — even though the evidence for opioids treating long-term, chronic pain is veryweak (despite their effectiveness for short-term, acute pain), while the evidence that opioids cause harm in the long term is very strong.

Painkillers proliferated, landing in the hands of not just patients but also teens rummaging through their parents’ medicine cabinets, other family members and friends of patients, and the black market.

As a result, opioid overdose deaths trended upward — sometimes involving opioids alone, other times involving drugs like alcohol and benzodiazepines (typically prescribed to relieve anxiety). By 2015, opioid overdose deaths totaled more than 33,000 — close to two-thirds of all drug overdose deaths.

Seeing the rise in opioid misuse and deaths, officials have cracked down on prescriptions painkillers. Law enforcement, for instance, threatened doctors with incarceration and the loss of their medical licenses if they prescribed the drugs unscrupulously.

Ideally, doctors should still be able to get painkillers to patients who truly need them — after, for example, evaluating whether the patient has a history of drug addiction. But doctors, who weren’t conducting even such basic checks, are now being told to give more thought to their prescriptions.

Yet many people who lost access to painkillers are still addicted. So some who could no longer obtain prescribed painkillers turned to cheaper, more potent opioids: heroin and fentanyl, a synthetic opioid that’s often manufactured illegally for nonmedical uses.

Not all painkiller users went this way, and not all opioid users started with painkillers. But statistics suggest many did: A 2014 study in JAMA Psychiatry found 75 percent of heroin users in treatment started with painkillers, and a 2015 analysis by the Centers for Disease Control and Prevention found that people who are addicted to painkillers are 40 times more likely to be addicted to heroin.

So other types of opioid overdoses, excluding painkillers, also rose.

That doesn’t mean cracking down on painkillers was a mistake. It appeared to slow the rise in painkiller deaths, and it may have prevented doctors from prescribing the drugs to new generations of people with drug use disorders.

But the likely solution is to get opioid users into treatment. According to a 2016 report by the surgeon general, just 10 percent of Americans with a drug use disorder obtain specialty treatment. The report found that the low rate was largely explained by a shortage of treatment options.

Some states, such as Louisiana and Indiana, have taken a “tough on crime” approach that focuses on incarcerating drug traffickers. But the incarceration approach has been around for decades — and it hasn’t stopped massive drug epidemics like the current crisis.