Wisconsin’s so-called “right-to-work” law, championed by Republican governor Scott Walker as he was mounting his run for president, was struck down on Friday as violating the state constitution.

Wisconsin’s attorney general, Brad Schimel, also a Republican, promised to appeal against the decision and said he was confident it would not stand. Schimel has not made a decision on whether to seek an immediate suspension of the ruling while the appeal is pending, spokesman Johnny Koremenos said.

“We are confident Wisconsin’s freedom-to-work law is constitutional and will ultimately be upheld,” Walker wrote on Twitter.

Three unions filed the lawsuit last year shortly after Walker signed the bill into law. So-called right-to-work laws prohibit businesses and unions from reaching agreements that require all workers, not just union members, to pay union dues. Twenty-four other states have such laws.

The unions argued that Wisconsin’s law was an unconstitutional seizure of union property since unions now must extend benefits to workers who don’t pay dues. Dane County circuit judge William Foust agreed.

He said the law amounts to an unconstitutional governmental taking of union funds without compensation, since under the law unions must represent people who don’t pay dues. That presents an existential threat to unions, Foust wrote.

“While [union] losses today could be characterized by some as minor, they are not isolated and the impact of [the law] over time is threatening to the unions’ very economic viability,” he wrote.

Foust noted that no other state court had struck down a right-to-work law on those grounds, but said he wasn’t obligated to follow other states. Republicans who backed the law dismissed the ruling, saying it will be reversed.

“Once again, a liberal Dane County judge is trying to legislate from the bench,” the Republican assembly speaker ,Robin Vos, said in a statement. “No one should be forced to join a union or pay union dues as a condition of employment.”

The law’s Democratic opponents hailed the decision as a victory for the middle-class and working families. “The extreme rightwing Republican agenda has been incredibly harmful to working people and businesses in Wisconsin,” said the Democratic assembly minority leader, Peter Barca.

Three unions – Machinists Local Lodge 1061 in Milwaukee, the Wisconsin AFL-CIO chapter and United Steelworkers District 2 in Menasha – brought the lawsuit. Erin Mediros, an attorney representing all three unions, did not immediately respond to a voicemail on Friday. Karen Hickey, a spokeswoman for the AFL-CIO’s Wisconsin chapter, also did not immediately respond to email and voicemail messages.

The decision overturning the law comes after the same judge last year declined to put it on hold while the lawsuit moved forward. Right-to-work supporters say such laws give workers the freedom to choose whether to join a union. Opponents say the laws weaken unions by depriving them of the dues from workers who choose not to pay them, resulting in lower wages and fewer employee rights. They also say the Republican-backed law is intended to undermine unions’ political power because unions tend to vote Democrat.

In 2014 the Indiana supreme court rejected two nearly identical challenges to that state’s right-to-work law. Those lawsuits alleged that the law unconstitutionally required unions to provide services to non-union workers without compensation.

The Wisconsin attorney general argued the law does not take anything from the unions since it technically does not remove any money currently in their accounts.

Walker launched his run for president just months after signing the law, and frequently mentioned it while campaigning. Months after taking office in 2011, Walker also signed a law that effectively ended collective bargaining for public sector workers.