The nation’s hospital groups sued the Trump administration on Wednesday over a new federal rule that would require them to disclose the discounted prices they give insurers for all sorts of procedures.

The hospitals, including the American Hospital Association, argued in a lawsuit filed in United States District Court in Washington that the new rule “is unlawful, several times over.”

They argued that the administration exceeded its legal authority in issuing the rule last month as part of its efforts to make the health care system much more transparent to patients. The lawsuit contends the requirement to disclose their private negotiations with insurers violates their First Amendment rights.

The administration wanted the disclosure rule, which would go into effect in 2021, to allow patients to better shop for deals on a range of services, from MRIs to hip replacements.

“Hospitals should be ashamed that they aren’t willing to provide American patients the cost of a service before they purchase it,” said Caitlin Oakley, a spokeswoman for the Department of Health and Human Services in an emailed statement. “President Trump and Secretary Azar are committed to providing patients the information they need to make their own informed health care decisions and will continue to fight for transparency in America’s health care system.”

While the administration is already requiring hospitals to post some of their list prices, the public outcry over surprise medical bills and high out-of-pocket costs led the administration to seek even more detail on rates. Patients have long complained that they are completely in the dark about what a doctor’s visit or surgery will cost until after they receive the bill. Knee surgery, for example, can cost thousands of dollars more at one hospital than at another in the same region.

At the heart of the administration’s efforts is an attempt to tackle rising hospital costs, which have outpaced the increase in physician prices, according to a recent study by health economists in Health Affairs. The economists estimated that hospital inpatient prices increased 42 percent from 2007 to 2014.

The hospital groups, which also include the Association of Medical Colleges, the National Association of Children’s Hospitals and the Federation of American Hospitals, which represents for-profit hospitals, argued in the lawsuit that the rule will not accomplish the administration’s aim of helping consumers avoid surprise bills. Three individual hospitals also joined the case.

“America’s hospitals and health systems remain committed to providing patients with the information they need to make informed health care decisions,” the lawsuit said. It contended that the rule “will generate confusion about patients’ financial obligations, not quell it.” The lawsuit was first reported by The Wall Street Journal.

The administration’s efforts to push the industry to make more information public to patients faces a real legal challenge, and it has been unsuccessful in earlier attempts. When the administration earlier tried to require pharmaceutical companies to disclose the list price of prescription drugs in television ads, the drug companies argued the Department of Health and Human Services had exceeded its regulatory authority and that the requirement also violated its First Amendment rights. A federal judge ruled last summer that H.H.S. exceeded its regulatory authority with the rule, which was seen as largely symbolic since list prices are not what patients typically pay.

A legal challenge to the rule had been expected. In fact, when he announced the hospital price disclosure rule, Alex M. Azar II, the health and human services secretary, was adamant that the rule would withstand a court challenge. “We may face litigation, and we feel we are on a very firm legal footing,” he said last month.

[Like the Science Times page on Facebook. | Sign up for the Science Times newsletter.]