PHOENIX — The Arizona Supreme Court handed a major victory Friday to backers of expanded Medicaid for 400,000 Arizona residents, upholding a hospital fee that covers the state’s share of the costs under the program.

The high court ruled unanimously on a challenge brought by Republican lawmakers who opposed the Medicaid expansion plan championed by former Gov. Jan Brewer in 2013. The challenge had wound its way through state courts ever since, being upheld all along the way.

Losing the assessment would have forced major enrollment cuts. The vast majority of funding for the expansion population comes from the federal government, but the state has to cover some costs.

The decision comes amid a national debate over Medicaid expansion, which was a centerpiece of former President Barack Obama’s health care law. President Donald Trump has been pushing to repeal the law since entering office. Republicans have been trying to dismantle the law in Congress but could not come up with enough votes in the Senate. Maine voters last week passed a measure that paves the way for Medicaid expansion in that state.

Lawyers with the Goldwater Institute represented the Republican lawmakers in Arizona. They argued that the hospital assessment was actually a tax that required a two-thirds vote under a voter-approved 1992 Constitutional amendment covering tax increases. Brewer only got a majority of lawmakers to back the plan.

The Goldwater Institute called the court decision a “blow to taxpayer rights.”

“The voters who limited the Legislature’s ability to raise taxes certainly didn’t intend to give even greater power to unelected officials to impose ‘assessments,'” Christina Sandefur, a Goldwater attorney, said in a statement. “This is a classic case of taxation without authorization.”

The state’s Medicaid agency and an advocacy group representing Medicaid recipients argued an exemption for fees set by state agencies means the hospital assessment is legal. Lower courts agreed with that argument.

Groups such as the Arizona Hospital and Healthcare Association praised the court’s decision.

“This is a great day for Arizona, and one we have awaited through a four-year legal fight,” the group said. “Had the high court instead opted to strike down the law that re-opened Arizona’s Medicaid rolls, the consequences would have been dramatic.”

The high court sided with the state, saying the fee was not a tax. It is “not prescribed by formula, amount or limit” and is set by the agency director, exemptions to the 2/3 vote requirement for new taxes.

The opinion was written by Chief Justice Scott Bales and joined by five members of the seven-member court and an appeals court judge. That judge was sitting in for Justice Clint Bolick, who was formerly the Goldwater Institute’s lead attorney, recused himself from the case.

The state’s hospitals paid $265 million in assessments in the last fiscal year based on the number of people they treated. In return, they got patients who were covered by Medicaid. The state hospital association backed the assessment because its members were losing hundreds of millions of dollars caring for uninsured low-income patients.

Brewer’s law restored coverage for childless adults earning less than 100 percent of the federal poverty level who had been covered in Arizona before the Great Recession sapped state revenues. It also extended coverage to all Arizonans legally in the country who earn up to 138 percent of the poverty level.

Brewer, a Republican, surprised many when she embraced the expansion. She angered many fellow Republicans with her efforts, which included calling a special legislative session after Republican House and Senate leaders stalled a vote for weeks.

She said in an interview Friday that she was “very gratified” that the court sided with her, saying a ruling the other way would have cost lives, decimated rural hospitals and hurt the state’s economy.

“Over 400,000 Arizonans now will continue to receive health care and mental health care and life-saving treatment, and that’s really important,” Brewer said. “Doing the right thing almost always means doing the hard thing, and I have absolutely, absolutely no regrets.”

With the expansion, about 1.9 million Arizona residents are now covered by Medicaid.