David Mitchell, the founder of Patients for Affordable Drugs, which advocates lower drug prices, said his group never thought the television-ad rule would get drugmakers to reduce their prices. “But if you take that away, at least it was something visible they could point to that they’d done,” he said.

Last week, the president said he would be issuing an executive order on drug pricing, but the breadth of the order remained unclear. His administration has proposed other moves, including allowing older adults to more directly benefit from drug rebates in Medicare, and tying the cost of some drugs to their price in other countries.

Republicans and Democrats in Congress have also put forward a range of legislation that would address the issue, from limiting out-of-pocket costs for people covered by Medicare to allowing the federal government to directly negotiate the price of drugs.

Merck, Eli Lilly and Amgen had sued to block the television-ad rule in June, arguing that forcing companies to disclose their list prices was beyond the reach of the federal government as well as a violation of the First Amendment. The companies also said many patients have health insurance that lowers their out-of-pocket costs, and seeing the higher list price might lead them to stop taking drugs they needed.

The Trump administration, including Secretary Alex M. Azar II of Health and Human Services, had argued that requiring such disclosure could shame the drugmakers into lowering their prices.

In a statement, Lilly said it was pleased with the ruling. “We are committed to working with stakeholders across the health care system to find better solutions for the larger issue, namely, lowering out-of-pocket costs for Americans who still struggle to pay for their medicines,” the company said.

AARP, which represents older Americans, expressed disappointment in the judge’s decision. “Today’s ruling is a step backward in the battle against skyrocketing drug prices and providing more information to consumers,” the group said. “Americans should be trusted to evaluate drug price information and discuss any concerns with their health care providers.”