(CNN) It's not uncommon for drug companies to try to keep generic versions of their best-selling drugs off the market. But this is a story about a drug company that went to extraordinary lengths to do so, calling into question the safety of a drug it had sold for years. When its plan didn't work, the company made an unusual decision.

As the opioid epidemic grew, Endo Pharmaceuticals took the extraordinary step in 2012 of pulling a version of one of its best-selling painkillers off the market, saying that the narcotic was susceptible to abuse.

Endo even unsuccessfully sued the US Food and Drug Administration that year to prevent the approval of any generic version of its drug, called Opana ER. The drugmaker argued that given a chance, drug abusers would crush and snort the generic pills, just as they had with the brand-name drug. Snorting intensifies the high but heightens the chance of overdosing.

It seemed as though a drug maker was taking selfless action to try to curb the growing opioid epidemic. But some industry observers say the story of Opana ER may better illustrate the lengths a drug company would go to in order to protect its profits.

Endo introduced a new formulation of Opana ER before phasing out the old one, selling two versions of the drug at the same time. Both drugs had the same active ingredient, oxymorphone. Both were extended-release pills for long-lasting effects. Both were called Opana ER.

Endo agreed to halt shipments of Opana ER starting September 1.

The difference was that the new version had a few different inactive ingredients, including a hard coating that made the pills harder to pulverize. Even so, addicts quickly learned how to cook the new painkiller and inject the liquid with a syringe.

Endo contended that the new Opana ER and its hard coating deterred abuse, but this summer, the FDA disagreed. In June, the regulatory agency concluded that the risks of new crush-resistant Opana ER outweighed its benefits and pressured Endo to stop selling it. It was the first time the FDA had taken steps to stop sales of a currently marketed opioid because of the consequences of abuse.

President Trump alluded to the drug last week when declaring the opioid epidemic a public health emergency . "We're requiring that a specific opioid, which is truly evil, be taken off the market immediately," he said.

Endo agreed to halt shipments of Opana ER starting September 1. But that's not the end of the drug's story.

Endo still has the patent on the original version of the drug, the one it fought to keep off the market. The FDA's action this summer didn't impact the crushable version Endo stopped selling in 2012.

So on August 8, Endo cut a deal with Impax Laboratories to split the profits of a generic version of its original drug. Endo is now poised to make money from a drug that it said shouldn't be on the market.

'It just doesn't seem right'

Endo's efforts to profit from a drug that it said was susceptible to abuse raises ethical questions, in the opinion of one member of the FDA advisory committee that recently reviewed Opana ER.

"They're the ones who called it dangerous and unsafe," said Suzanne Robotti , who is also the founder of the MedShadow Foundation, a patient advocacy group. "It just doesn't seem right."

Dr. Michael Carome , director of health research for the consumer group Public Citizen, was harsher in his criticism. "The pharmaceutical industry is solely driven by its desire to make profits and boost its bottom line," Carome said. "Here's a situation where the company is talking out of both sides of its mouth, depending on what will make them money."

Endo defended its decision to cut the deal with Impax.

"The FDA is charged with -- and makes -- the sole determination of whether pharmaceutical products are safe and effective," the company told CNN.

"In June 2017, the FDA requested that Endo voluntarily withdraw the formulation of Opana ER that is designed to be crush resistant due to unintended use and misuse. ... In July 2017 the Company, after careful consideration, decided to voluntarily withdraw it from the market. In the case of the prior formulation of Opana ER, the FDA determined that the product should remain on the market."

The FDA declined to comment on why it left the generic version on the market but told CNN it is assessing the abuse patterns for that drug.

History of keeping generics off the market

Endo Pharmaceuticals has a long history of trying to keep generic versions of Opana ER off the market. Because generic drugs are so similar to their brand-name counterparts, a generic drug's maker can piggyback off the FDA approval of the brand-name drug.

Timeline of Opana ER June 22, 2006: FDA approves Opana ER.

FDA approves Opana ER. November 15, 2007: Endo sues Impax Laboratories for patent infringement after Impax says it intends to market a generic version of Opana ER.

Endo sues Impax Laboratories for patent infringement after Impax says it intends to market a generic version of Opana ER. December 9, 2011: FDA approves a new crush-resistant version of Opana ER.

FDA approves a new crush-resistant version of Opana ER. February 2012: Endo begins selling crush-resistant Opana ER and phasing out original Opana ER without yet raising safety concerns with FDA.

Endo begins selling crush-resistant Opana ER and phasing out original Opana ER without yet raising safety concerns with FDA. August 10, 2012: Endo petitions the FDA to keep a generic version of the original Opana ER off the market because of safety concerns.

Endo petitions the FDA to keep a generic version of the original Opana ER off the market because of safety concerns. November 30, 2012: Endo sues the FDA to keep generic version off market, demanding a decision by end of the year.

Endo sues the FDA to keep generic version off market, demanding a decision by end of the year. January 1, 2013: Impax is scheduled to launch a generic version of Opana ER.

Impax is scheduled to launch a generic version of Opana ER. May 2013: FDA denies Endo's request to declare original Opana ER unsafe and keep generics off the market.

FDA denies Endo's request to declare original Opana ER unsafe and keep generics off the market. March 14, 2017: FDA advisory committee votes 18 to 8 that the risks of crush-resistant Opana ER no longer outweigh the benefits. Abuse of the reformulated drug appears to have increased and was linked to outbreaks of hepatitis C, a rare blood disorder and HIV.

FDA advisory committee votes 18 to 8 that the risks of crush-resistant Opana ER no longer outweigh the benefits. Abuse of the reformulated drug appears to have increased and was linked to outbreaks of hepatitis C, a rare blood disorder and HIV. June 8, 2017: FDA asks Endo to take Opana ER off the market.

FDA asks Endo to take Opana ER off the market. July 6, 2017: Endo agrees to pull Opana ER off the market.

Endo agrees to pull Opana ER off the market. August 8, 2017: Endo announces a deal with Impax Laboratories to split profits on generic version of original Opana ER -- the same drug Endo tried to keep off the market for safety reasons.

The FDA approved oxymorphone as a painkiller in 1959, but the pill form was voluntarily taken off the market in 1982. Endo decided 15 years later to revive the drug as an extended-release pill. In 2006, the FDA approved Opana ER.

The extended-release pill comes in higher doses that are slowly released in the body for up to 12 hours. Opana ER is more potent than its two competitors, morphine and oxycodone, and was intended for use for moderate to severe pain for patients who needed 24-hour relief.

immediately for patent infringement. The drugmakers settled in 2010, with Impax agreeing to wait until 2013 to launch its generic. In 2007, Impax sought FDA approval to sell a generic version of Opana ER, but Endoimmediately sued for patent infringement. The drugmakers settled in 2010, with Impax agreeing to wait until 2013 to launch its generic.

But as that date drew near, Endo tried again to keep Impax from selling a generic version of Opana ER.

That's when Endo decided to pull the original formulation of Opana ER off the market, saying the drug was susceptible to abuse. Endo petitioned and later sued the FDA to force the agency to declare formally that the original formulation was withdrawn for safety reasons. Doing so would keep generic drugmakers from piggybacking off the drug's FDA approval.

Endo filed the FDA lawsuit only about a month before Impax was scheduled to sell the generic drug. The drugmaker urgently sought a decision by the end of the year. But the FDA persuaded the court to dismiss the lawsuit, telling it "Endo's self-inflicted December 31 deadline is a thinly-veiled attempt to maintain its market-share and block generic competition from Impax."

Opana ER was one of Endo's best-selling brand-name drugs. In 2012, net sales of the narcotic amounted to nearly $300 million, or 10% of Endo's total revenues.

Endo justified withdrawing the original version of Opana ER by telling the FDA that it saw misuse of Opana ER soar after Purdue Pharma introduced a crush-resistant version of its top-selling Oxycontin in 2010. The company cited research showing that abuse of Opana ER rose 111% from August 2010 through March 2012.

Endo said it introduced a crush-resistant version of Opana ER "in recognition of increased reports of the potential for abuse and misuse" of the original formulation.

However, the FDA says Endo never told it about these safety concerns until months after it began selling the crush-resistant pill and phasing out the original one.

Even when Endo announced the FDA's approval of crush-resistant Opana ER in December 2011, the company said, "It has not been established that this new formulation of Opana ER is less subject to misuse, abuse, diversion, overdose, or addiction."

In the lawsuit, the FDA asked why Endo continued to sell original Opana ER if it thought the drug was unsafe.

Allowed to join the lawsuit, Impax put it more bluntly: "Contrary to its insincere concern about public safety, Endo distributed the allegedly 'dangerous' Opana ER for years, and then apparently continued distributing it for up to nine months even after obtaining approval to market (crush-resistent) Opana ER."

In 2013, the FDA ruled on Endo's petition, saying that Opana ER "was not withdrawn from sale for reasons of safety and effectiveness." The ruling was based on the company's failure to present sufficient evidence that the crush-resistant version of Opana ER was less likely to be abused than the crushable version. The decision allowed Impax to sell a generic version of Opana ER.

Last year, the Federal Trade Commission sued Endo and Impax, alleging that their 2010 agreement to delay the launch of a cheaper generic until 2013 violated federal consumer laws.

The FTC alleged that Endo paid Impax more than $110 million for the delay. The federal lawsuit also alleged that Endo launched its crush-resistant pill "to protect and extend its Opana ER franchise in the face of potential generic entry."

Endo settled the FTC lawsuit in January, promising not to cut any deals intended to keep generic drugs off the market. Impax is still contesting an administrative complaint from the FTC on the same allegations.

Abuse of new drug goes up

Meanwhile, the FDA decided to take a closer look at Opana ER. Over time, data from drug rehabilitation centers showed that as users learned to inject the reformulated drug, the rate of overall abuse actually increased.

Opana ER is not the only opioid being abused, but medical researchers were linking its misuse to outbreaks of hepatitis C as well as a rare but deadly blood disorder affecting at least 30 people in Tennessee and North Carolina and an HIV epidemic affecting more than 200 people in southern Indiana

Opana can be bought illegally for a hefty price on the street, where the drug is sometimes called "biscuits," "O bomb" and "stop signs." Because it is so potent, addicts often split the dose with others. The high is over quickly, so addicts shoot up several times a day. This year, an FDA advisory committee said these factors may have encouraged needle sharing and the spread of disease.

Vice President Mike Pence, then governor of Indiana, reluctantly gave in to calls in 2015 for a needle exchange -- replacing used needles with sterile ones -- to stop the spread of HIV in his state linked to Opana ER abuse.

In March of this year, an FDA advisory committee held two days of hearings on crush-resistant Opana ER. The group concluded by a vote of 18-8 that the risks of the newer version of the drug outweighed its benefits.

But before pulling the drug, the Pennsylvania-based drugmaker went into negotiations with Impax to settle ongoing litigation. The deal announced in August was to split the profits on generic extended-release oxymorphone for the next 11 years, starting January 1, 2018.

Endo told CNN that the deal "allows Endo to be fairly compensated for Impax's license to use Endo's valuable intellectual property in offering the product for use as intended."

Last year, Impax made $72.7 million from sales of the generic drug. Endo's sales of Opana ER amounted to about $159 million last year.

Follow CNN Health on Facebook and Twitter See the latest news and share your comments with CNN Health on Facebook and Twitter.

During a recent conference call with investors, Paul Bisaro, president and chief executive officer of Impax, said, "I think our challenge will be to make sure that patients and caregivers understand that if their patients are on oxymorphone extended-release product because they prefer that, that that product remains available."

Asked by CNN about the safety of the generic, Impax issued a statement: "Patient safety is very important to us. We believe that our product is an effective therapy for patients with chronic pain when used as directed by a physician and in accordance with the label/package instructions."