A man has been sentenced to more than 17 years in prison for directing fentanyl-laced pills to be given to rapper Mac Miller before the star died of an overdose, officials announced Monday.

Stephen Andrew Walter, 48 and of Westwood, pleaded guilty to one count of distribution of fentanyl in November 2021, according to the U.S. Attorney’s Office.

The offense carries a 20-year mandatory minimum prison term, but under a plea agreement, Walter will instead serve a 17-year prison term, according to the sentencing memorandum.

Walter knew that the pills contained fentanyl or some other federally controlled substance, the memorandum states.

He is one of three people charged in the overdose death of Miller, a famed 26-year-old rapper whose real name was Malcolm James McCormick.

Former West Los Angeles resident Ryan Michael Reavis was sentenced last month to nearly 11 years in prison after also pleading guilty to distribution of fentanyl.

A case against 30-year-old Cameron Pettit of West Hollywood is pending.

Reavis knowingly distributed the counterfeit pills to Pettit on Sept. 4, 2018, according to the Department of Justice. Shortly after, at the direction of co-defendant Walter, Pettit gave the fentanyl-laced pills to the rapper.

Miller got the pills about two days before he suffered the fatal drug overdose on Sept. 7, 2018.

The star’s personal assistant found him unresponsive in his Studio City home, and paramedics pronounced him dead at the scene.

The rapper died from an accidental overdose due to a combination of alcohol and drugs, including fentanyl, the L.A. County coroner’s report said at the time.

Fentanyl is a synthetic opioid that is around 100 times stronger than morphine and 50 times more potent than heroin, according to the U.S. Drug Enforcement Administration. Just 2 milligrams can be lethal, depending on a person’s body size, tolerance and past use. 

Synthetic opioids like fentanyl are the primary driver of overdose deaths in the country, according to the Centers for Disease Control and Prevention.