A Wisconsin law barring unions from requiring workers in the private sector to pay the equivalent of union dues was struck down late Friday after a judge deemed it a violation of the state’s Constitution.

Democrats and union leaders in the industrial Midwest, a region where organized labor has been weakened by a series of new laws in recent years, cheered the ruling, but its fate almost immediately seemed uncertain. Republican leaders in Wisconsin, where a conservative bloc holds a majority on a sharply divided State Supreme Court, pledged to appeal the lower court’s ruling and said they felt confident that the law would ultimately stand.

The law, which was pressed through Wisconsin’s legislature in March 2015 by Republican leaders and signed by Gov. Scott Walker as he was preparing to run for president. It made Wisconsin the 25th state to adopt such legislation, following closely behind Indiana and Michigan. In Wisconsin, the law went into effect immediately, over the objections of labor leaders, who argued that the measure was meant to weaken their power and would lower workers’ wages.

In his ruling, Judge C. William Foust of Dane County Circuit Court agreed with three unions that had contested the measure, saying that the law amounted to a taking of their property without just compensation. The unions — local chapters of the International Association of Machinists, United Steelworkers and the A.F.L-C.I.O. — contended that the law added up to a seizure of their property since they were now required to provide union benefits like collective bargaining to workers who opted not to pay the equivalent of dues.