This article was written through collaboration between The New York Times and ProPublica, the independent, nonprofit investigative journalism organization.

It’s standard advice for consumers: If you are prescribed a medicine, always ask if there is a cheaper generic.

Nathan Taylor, a 3-D animator who lives outside Houston, has tried to do that with all his medications. But when he fills his monthly prescription for Adderall XR to treat his attention-deficit disorder, his insurance company refuses to cover the generic. Instead, he must make a co-payment of $90 a month for the brand-name version. By comparison, he pays $10 or less each month for the five generic medications he also takes.

“It just befuddles me that they would do that,” said Mr. Taylor, 41.

A spokesman for his insurer, Humana, did not respond to multiple emails and phone calls requesting comment.

With each visit to the pharmacy, Mr. Taylor enters the upside-down world of prescription drugs, where conventional wisdom about how to lower drug costs is often wrong.

Consumers have grown accustomed to being told by insurers — and middlemen known as pharmacy benefit managers — that they must give up their brand-name drugs in favor of cheaper generics. But some are finding the opposite is true, as pharmaceutical companies squeeze the last profits from products that are facing cheaper generic competition.

Out of public view, corporations are cutting deals that give consumers little choice but to buy brand-name drugs — and sometimes pay more at the pharmacy counter than they would for generics.

The practice is not easy to track, and has been going on sporadically for years. But several clues suggest it is becoming more common.

In recent months, some insurers and benefit managers have insisted that patients forgo generics and buy brand-name drugs such as the cholesterol treatment Zetia, the stroke-prevention drug Aggrenox and the pain-relieving gel Voltaren, along with about a dozen others, according to memos and prescription drug claims that pharmacies shared with ProPublica and The New York Times. At the same time, consumers are sounding off on social media.

Now it appears the practice is spreading to biosimilars, the competitors for expensive, complex biologic drugs that are beginning to arrive on the market.

Consumers have become increasingly angry over what they pay for drugs, and that outrage has caught the attention of lawmakers from both parties. Democrats have identified lowering drug prices as a pillar of their economic agenda, and President Trump has raised the issue repeatedly. But for now, solutions have proved elusive.

The continued success of the brand-name drug Adderall XR, long after generic competitors arrived on the market, is a case in point.

Dr. Lawrence Diller, a behavioral pediatrician in Walnut Creek, Calif., said he began noticing “very odd things” going on with Adderall XR and other attention-deficit drugs about two years ago. He began receiving faxes from pharmacies telling him that he had to specify that patients required brand-name versions of the drugs.

He had been practicing for 40 years, but until then had never had a pharmacy tell him that he had to prescribe a brand-name drug instead of a generic.

“It’s Alice-in-Wonderland time in the drug world,” he said.

Some insurers require members to have prescriptions filled with brand-name drugs and do not charge them more than for generics. But 29 percent of Americans with health insurance paid for by their employer have a high-deductible insurance plan. They acutely feel the cost difference between branded and generic drugs because they often have to pick up the full sticker price of medications until they have paid out thousands of dollars.

Naomi Freundlich, a Brooklyn writer, had been buying the generic version of Adderall XR for two years to treat her son’s attention-deficit hyperactivity disorder. Her family had a $3,000 annual deductible, and the relatively lower price helped keep medical costs down.

Then, in 2014, her pharmacist told her that her insurance plan would cover only the brand-name drug, which cost her family some $50 more a month than the generic. If she paid for the generic herself, it would not have counted toward her deductible. Ms. Freundlich complained to her insurer, UnitedHealthcare, but could not get a clear answer.

“It’s hard to explain because it doesn’t really make sense,” she said.

UnitedHealthcare has continued to favor Adderall XR and certain other brand-name drugs over generics, according to claims provided by independent pharmacists and reviewed by ProPublica and The Times. The insurer also recently told health providers that it preferred Remicade, the expensive rheumatoid arthritis drug made by Johnson & Johnson, over biosimilars that have a lower list price and are just beginning to come on the market.

A spokesman for UnitedHealthcare, Matthew N. Wiggin, said the insurer does at times prefer brand-name drugs. “By providing access to these drugs at a lower cost, we are able to improve affordability for our customers and members,” he said in an email.

Asked whether consumers sometimes ended up paying more because of these choices, he said pharmacies and doctors could seek an exemption from the insurer if they wanted the generic instead. Several patients said they had not been told of that option.

Shire, the maker of Adderall XR, and some other brand-name drug manufacturers are no longer content to allow sales of their products to plummet when generic competitors arrive on the market. Instead, they are negotiating deals with insurers and pharmacy benefit managers to give priority to their versions. Consumers are given no details about these deals.

A Shire spokeswoman said the company had been able to hold on to market share for Adderall XR by offering insurers and government programs prices that are competitive with those of generic manufacturers.

Adderall XR, the long-acting version of Shire’s popular treatment Adderall, had for years been the company’s top-selling product, bringing in $1.1 billion in sales in 2008, about one-third of its revenue that year.

But mindful that its blockbuster could soon face generic competition, Shire acted aggressively to protect its franchise.

First, in the mid-2000s, Shire sued generic drug companies to block them from bringing cheaper copies to the market, alleging patent infringement. Then, it made deals with two makers of generic drugs to sell authorized copies of its drug, a tactic in which the branded manufacturer supplies its product in exchange for a share of royalties. Those agreements soured after the two companies, Teva Pharmaceuticals and Impax Laboratories, accused Shire of not playing fair by failing to supply them with enough pills to compete in the marketplace. More lawsuits ensued, followed by settlements.

Then, a few years ago, Shire tried a new tactic: giving ever-larger discounts to pharmacy benefit managers and insurers for preferential treatment over the generics. That did not mean lowering the list price of the drug, but rather negotiating rebates that were paid not to the patients but to insurers and middlemen such as CVS Caremark.

Benefit managers and insurers have been passionate advocates of generic drugs, arguing that the cheaper products save patients and their employers billions of dollars. Indeed, generic drugs have come to dominate the market, and today account for nearly 90 percent of all prescriptions filled in the United States.

Shire has managed to hold on to a much larger share of the market through its deals than most companies do when their drugs come off patent and face generic competition.

Adderall XR, the brand-name version of extended-release mixed amphetamine salts, accounted for 29 percent of the 13.1 million prescriptions for the drug in 2016, according to QuintilesIMS, a health information company that purchases the data from pharmacies and sells it to clients that include drug companies. The average market share of brand-name products dwindles to less than 6 percent two years after the first generic competitor arrives, according to QuintilesIMS.

The list price of Adderall XR has remained $7.12 per pill since mid-2012. But according to data from SSR Health, a research firm that tracks drug prices, the portion that Shire keeps has steadily declined.

In the first quarter of 2017, SSR estimated that Shire kept only $1.73, down from $2.93 per pill in the first quarter of 2013. Shire does not break out how much it pays to each middleman in the system, from distributors to pharmacy benefit managers.

But Ryan Baum, an analyst at SSR Health, said it was clear that Shire’s declining share of the list price reflected “just a really aggressive instance of trying to hang on.”

“It’s irrefutable, really,” he added.

In contrast, the generics cost as low as $3.89 per pill, but that does not include unspecified concessions that generic makers offer to pharmacies and distributors, according to Truven Health Analytics, another research firm that tracks the prices wholesalers pay for drugs.

A spokeswoman for Shire, Gwendolyn Fisher, said that while Shire did not make decisions about how much patients paid in out-of-pocket costs, “Shire is helping to deliver cost savings to the system and greater patient access to an important medicine.”

Shire said last week that it was considering spinning off the portion of its business that sells attention-deficit drugs in order to focus on developing rare-disease treatments.

Generic drug makers say they have seen an increase in efforts by manufacturers of brand-name drugs to fight to retain sales after they lose patent protection.

“You definitely see a much more aggressive posture than you used to see,” said Christine Baeder, senior vice president for customer and marketing operations at Teva, the world’s largest generic drug manufacturer.

In December, CVS Caremark, one of the largest benefit managers, sent a memo to pharmacies informing them that some of its Medicare prescription drug plans would cover only brand-name versions of 12 drugs. Some of the drugs, such as the antipsychotic medication Invega, have had generic competitors for over a year.

Also on the list was Copaxone, a brand-name drug sold by Teva that treats multiple sclerosis and that recently lost patent protection on its daily injection. Though Teva primarily makes generic drugs, in a twist it has taken a page from brand-name manufacturers to preserve sales of one of its key products.

In a statement, Teva said many patients had moved to its three-times-weekly version of Copaxone, for which there is no generic, but said it wanted to ensure that patients who “wish to remain on therapy continue to have access.”

Consumers taking other medications said they had experienced the same phenomenon. Lisa Hopkins, a disabled food and nutrition supervisor in Pennsylvania, went to fill a prescription for the anti-inflammatory Voltaren gel this year.

Ms. Hopkins, 52, said her pharmacist had told her that her drug plan, CVS’s SilverScript, denied her claim because it was for a generic.

“I said to the lady at the insurance company, ‘That’s really, really odd to me,’” Ms. Hopkins said. “She said: ‘Yes. It’s happening more and more that the name brand is covered but the generic isn’t.’”

Ms. Hopkins has osteoporosis and bulging spinal disks and has been on disability for almost a decade. She is covered through Medicare and receives extra help from the government for her medications, lowering her out-of-pocket costs. That means that when her drugs cost a lot, taxpayers pay the bill. By law, Medicare cannot negotiate directly with drug manufacturers and instead gets a share of any rebates collected by insurers and benefit managers, like CVS Caremark, which operate Medicare’s drug plans.

In an email, a spokeswoman for CVS Caremark, Christine Cramer, said consumers never pay more in the rare instances in which the company favors a brand-name drug over a generic. “This generally occurs when there is limited or no competition among generics,” she said.

Pharmacists say they are noticing the trend, too, and it takes time to understand the denied claim and pursue a remedy, including sometimes calling the doctor. While favorable treatment for a brand-name drug doesn’t happen all the time, it is startling when it does, said Robert Frankil, president of Sellersville Pharmacy Inc. in Pennsylvania, which owns two pharmacies.

“There’s only one reason why they’re requiring you to use a more expensive product,” Mr. Frankil said. “Because somewhere down the road, somebody is earning more money.”