SALT LAKE CITY — A drug ring that prosecutors say would ultimately send thousands of fake prescription painkillers laced with potentially deadly fentanyl across the United States began in the Orem basement of two roommates in their 20s.

Five years ago, Drew Crandall had dropped out of the University of Utah and was struggling to cover rent and payments on $40,000 in student loans, especially after losing his job at the eBay call center where he and his roommate Aaron Shamo had worked, he said in federal court in Salt Lake City Thursday.

His testimony was part of the trial for Shamo, 29, the man prosecutors have identified as a kingpin and have tied to the 2016 overdose death of a 21-year-old California man.

Shamo’s defense attorney Greg Skordas has maintained his client did commit some crimes in selling the drugs, but did not cause anyone’s death and was not a kingpin.

In Orem, Shamo had suggested he and Crandall earn extra cash at first by bitcoin mining, or recording the cryptocurrency transactions in exchange for payment, and later by selling Adderall, the prescription medicine used to treat attention deficit hyperactivity disorder, Crandall said.

As the operation evolved to sell cocaine, counterfeit Xanax, Oxycontin and finally the powerful and potentially deadly fentanyl, Crandall described feeling increasingly uncomfortable and trying to distance himself from Shamo.

He eventually gave up his one-third ownership stake in the business in exchange for a $40,000 payout before leaving the country and moving to New Zealand with his girlfriend because “I wanted to separate myself from all of that,” he said.

When Shamo said he couldn’t cover later installments and offered Crandall work handling customer service instead, Crandall accepted. He ultimately handled complaints of missing orders and faulty products halfway around the world for the seller known as Pharma-Master on the darknet marketplace Alphabay.

Crandall hadn’t realized until then that many of the pills contained fentanyl, he testified.

“I’m absolutely ashamed about what I did,” a shackled Crandall said as he cried on the witness stand Thursday. “I enabled people with an addiction to further that. I did terrible things and I did it all for money.”

The drugs were sold using bitcoin and at one point raked in $2.8 million in less than a year, court documents say. The ring allegedly sold hundreds of thousands of fentanyl pills to individual people and to drug dealers.

Crandall’s family members could be seen wiping tears from their faces at times during his roughly three hours of testimony. They declined comment outside the courtroom.

Crandall and five other defendants in the case have reached agreements with prosecutors. None faced the same charge Shamo does of distributing fentanyl resulting in death.

Crandall pleaded guilty last year to conspiracy to distribute fentanyl and alprazolam — commonly known as Xanax — and conspiracy to commit money laundering. He faces up to life in prison but prosecutors have agreed to recommend a sentence at the low end of a guideline range determined by the judge.

Crandall portrayed Shamo as the head of the operation with control over purse strings, hiring employees and deciding what to sell, while Crandall helped mix the drugs in mason jars, package and ship them and set up a pill press.

From Mormon kid to alleged drug kingpin: Inside the rise and fall of Aaron Shamo

When one customer complained a friend had overdosed, Crandall said, “I started to freak out.” He recalled Shamo telling him, “I’ll bet this guy’s just faking us.”

Despite Crandall’s misgivings, he continued to do the job that supplemented his housekeeping and restaurant jobs in New Zealand and that would help fund his travels to Thailand, Malaysia and other countries, Skordas pointed out.

“You weren’t so upset with what was going on that you got out if it,” Skordas said during cross-examination.

“I did make a break at one point, but I did return to it,” Crandall replied. He acknowledged it was “easy money.”

In November 2016, after conducting surveillance on Shamo for weeks, the federal Drug Enforcement Administration and local police raided his Cottonwood Heights home, where they seized $1.2 million in cash. Crandall was in Laos at the time and scrambled to delete any evidence of his ties to the operation, he said.

When he arrived in the United States to get married in Hawaii in 2017, he was arrested at the airport.

The trial is expected to last a month in Salt Lake City’s U.S. District Court.