At 22, he successfully kicked the heroin addiction that had derailed his life soon after his college graduation. At 25, he moved back to the Philadelphia suburbs and opened a rehab center to help others recover.

And by 28, his success story had begun earning him prominent speaking invitations from community leaders and elected officials, including Attorney General Josh Shapiro in Pennsylvania, a state gripped by an addiction crisis responsible for thousands of deaths.

Yet even as his star was rising, Joseph Lubowitz was illegally profiting from that epidemic and the very patients he had publicly pledged to help, he acknowledged Wednesday in a federal court hearing in West Palm Beach, Fla.

Lubowitz, now 30, of Philadelphia, pleaded guilty to one count of conspiracy to commit health care fraud, admitting he had accepted more than $21,000 in kickbacks for sending his patients to recovery facilities in Delray Beach, Fla., where prosecutors say they were “used like cattle” solely to generate revenue.

Managers of Real Life Recovery, a rehab center, and Halfway There, a sober-living house, allegedly offered patients free airfare, rent, and other perks, and ignored their continued drug use as long as they maintained insurance that would cover the expensive and often unnecessary treatments and tests they received there.

Some patients Lubowitz sent to Florida were given urine tests up to four times a week, each costing as much as $9,000. In all, prosecutors said, the scheme generated $3 million to $9.5 million in fraudulent insurance billings for the centers’ managers between 2011 and 2015.

“Patients’ urine was the ‘liquid gold’ used to earn the scheme’s illegal gains,” Assistant U.S. Attorney James V. Hayes wrote in a court filing last month that accused Lubowitz and his codefendants of netting millions in profits on the backs of “young, addicted, vulnerable, and desperate individuals dealing with serious drug and alcohol addictions.”

As public and private health insurers have devoted more money and resources to helping their customers battle addiction in the midst of a nationwide opioid crisis, similar scams have cropped up with alarming frequency, law enforcement officials say.

In March, Shapiro — at whose side Lubowitz appeared at several events before his arrest last year — announced a slate of indictments against top-level executives at Liberation Way, a now-shuttered Bucks County rehab facility and sober home, allegedly engaged in a scheme much like the one prosecutors have outlined at Real Life Recovery and Halfway There.

The attorney general did not learn of Lubowitz’s involvement in the Florida scheme until after his indictment last June along with two of the businesses’ managers, Shapiro’s spokesperson, Joe Grace, said in a statement.

“This individual was one of many advocates for people in recovery who appeared at events with the Office of the Attorney General as part of our multipronged efforts fighting the opioid epidemic across Pennsylvania,” it read.

But before Lubowitz’s arrest, Shapiro and other community leaders routinely turned to him as a real-life success story they were eager to highlight while touting their own efforts to stem the tide of opioid-related deaths.

A former varsity athlete at Upper Dublin High School, Lubowitz spoke engagingly about his high school addiction to alcohol and marijuana, which progressed to heroin after he graduated from Pennsylvania State University.

In public appearances, he explained his choice once he achieved sobriety to open his rehab facility — Humble Beginnings, with branches in Willow Grove and Cherry Hill — to help others do the same in the region where his own struggles with drugs had begun.

In recognition of Lubowitz’s story, Shapiro chose the Upper Dublin football field as the location of a splashy 2017 news conference at which he announced a high-profile investigation into the way drug companies market and sell opioid painkillers.

But even as Lubowitz stood alongside Shapiro and other recovery advocates that day, federal authorities in Florida were probing the regular payments he was receiving from Real Life Recovery and Halfway There in violation of Florida’s patient brokering laws.

Although Lubowitz pleaded guilty Wednesday only to accepting illegal kickbacks from those companies, prosecutors have alleged he received similar payoffs from five other Palm Beach County rehab facilities and sober homes in exchange for sending them addicted drug users from Pennsylvania and New Jersey.

In court papers, Lubowitz originally claimed that the payments were part of general marketing agreements he signed with those companies and that he was unaware of how Real Life Recovery was using patients to illegally maximize their insurance billings.

But prosecutors balked at those claims, dismissing the consulting agreements Lubowitz signed as shams and citing a custodian at the facility who told an FBI agent that knowledge of its illegal billing practices was so widespread, even he was aware.

“And if the janitor knows about it,” the man said, according to grand jury testimony quoted in court filings, “what does that tell you?”

One patient, prosecutors said, was tested 38 times in four months and tested positive for drugs all but seven. The sober house never kicked him out or sent him back for more treatment, while the facility continued to test him and billed his insurance carrier $190,000.

Another woman was tested 11 times in roughly a month, with results showing continued drug use. In all, the facilities billed her insurance more than $488,000 for urine testing and other services.

As part of his plea agreement Wednesday, Lubowitz agreed to admit that he was aware of the unnecessary testing and insurance claims. He also agreed to cooperate — and potentially testify — against two top executives for the now-closed recovery centers should they take their case to trial in August. (A third codefendant, a Florida patient broker, also pleaded guilty Wednesday.)

But his stint as a prominent recovery advocate appears to be over. Humble Beginnings, his rehab center, dumped him as CEO after his arrest, and he now faces the prospect of up to 10 years in prison at a sentencing hearing scheduled for September.

He is now, he said in court filings, hoping to buy a franchise selling “smoothie bowls” in New York, Maryland, or Delaware.

“The evidence shows that Mr. Lubowitz played a very small role in the case,” his Miami-based attorney, Edward Robert Shohat, wrote in an email Wednesday. “We expect that he will be sentenced accordingly.”