Connecticut hospitals have taken the first step toward a legal battle with the state over a tax they assert is unconstitutional and has cost them tens of millions of dollars in recent years.

The Connecticut Hospital Association and 24 hospitals, including Danbury, Bridgeport, Norwalk, Stamford and Greenwich, have filed documents with the state departments of revenue and social services claiming the hospital tax violates state and federal laws, as well as the state and federal constitutions.

The filings request that the two agencies issue declaratory rulings that the tax is invalid and unenforceable.

“Our goal is fairly simple,” said Stephen Frayne, senior vice president of health policy at the Connecticut Hospital Association. “We’d prefer to be taking care of patients rather than have to fight this out in the court system, but we are left with no choice because we’re being taxed into oblivion.”

“The state’s hospital tax is preventing us from doing the work we know our community expects and deserves,” said Dr. John Murphy, president and CEO of the Western Connecticut Health Network, in a statement. “We have no choice but to fight for what we know is right.”

The state began collecting the hospital tax in 2012, intending to redistribute the proceeds to the hospitals as a way of drawing down matching federal grants. That year, the hospitals paid about $350 million in taxes, Frayne said, and received about $400 million in state and federal funds.

But when the state began experiencing severe budget pressures, it started returning less and less to the hospitals. This year, hospitals are projected to owe $556.1 million in taxes, but are slated to receive only the $164.3 million provided in December’s budget deal.

The state agencies have 60 days to respond to the two filings, which were dated Nov. 30. If they uphold the tax, the way is open for the association and the hospitals to file suit.

Hospital and CHA officials say they hope not to take that step. But if they do so, they won’t be the first in the region; their counterparts in New Hampshire fought a similar fight and were able to force a settlement that restored the flow of revenue to the hospitals.

The New Hampshire hospital tax had been collected for decades, with the money being returned to hospitals to help care for uninsured patients.

In 2011, ten of the state’s largest hospitals, including Dartmouth-Hitchcock Medical Center, filed a federal suit against the state over the way the money was being redistributed. Some hospitals were getting nothing at all.

“It was an untenable situation that endangered our ability to provide care for our patients,” said Frank McDougall Jr., vice president of government relations at Dartmouth-Hitchcock. “We gathered as a group and talked about this, and saw no other alternative than to bring the federal suit.”

Separately, a rehabilitation hospital and three acute-care medical hospitals sued the state, claiming the tax was illegal because it didn’t apply to other health care providers offering similar services.

In both cases, state judges ruled that the tax was unconstitutional.

In 2014, the state reached a settlement with 25 hospitals. Under the agreement, larger hospitals will get about half what they pay for uncompensated care over the next two two-year budget cycles, and smaller hospitals about 75 percent, in exchange for dropping the lawsuits. The state also agreed to put all money raised from the tax in a trust fund for use only to support Medicaid.

The years of discord and disagreement between the state and hospitals seems to be in the past.

“We feel like we’ve made tremendous strides in those relationships,” said Steve Ahnen, president of the New Hampshire Hospital Association.

But Ahnen said the work isn’t over.

“Ensuring that this agreement stays in place is absolutely essential,” he said. “When the the legislature was considering the current two-year budget, there was an attempt to undo the settlement, to pull some money away. We had to fight quickly to make sure that didn’t happen.”

In Connecticut, feuding over the hospital tax has intensified in recent months.

In September, Gov. Dannel P. Malloy slashed the state budget, cutting the $255.9 million originally budgeted for hospitals to $64 million. In response, the Connecticut Hospital Association started an aggressive multimedia online campaign to reverse the cuts.

The governor countered by shaming health care executives over their multimillion-dollar salaries and the hospitals’ supposedly high profit margins.

In response to the Nov. 30 filing, Department of Social Services spokesman David Dearborn cited figures suggesting that state hospitals had more than $900 million in profits last year — although the CHA disputes those figures as grossly misleading.

Dearborn also contended that Medicaid payments to hospitals have increased over the last decade, and that hospitals are seeing fewer patients without coverage because of Medicaid expansion under the Affordable Care Act.

“Even in an industry that made $916 million last year alone — and one in which there is exorbitant CEO pay — the hospital association is asking Connecticut taxpayers to foot more of the bill,” said Dearborn in a statement.

Perhaps signaling where the dispute is heading, the CHA has hired the New Hampshire law firm involved in the hospital cases against that state to advise it in its proceedings against Connecticut.

“We had hoped common sense would prevail in resolving this matter, but the process has taken too long and yielded too little,” said Murphy. “After several years of refusing to consider our appeals, negotiations and proposed solutions, the governor has forced us to pursue legal action to repeal a tax that is unfortunate, unfair and unconscionable.”