MADISON, Wis. — The Wisconsin Supreme Court has upheld the 2011 law that effectively ended collective bargaining for most public workers, sparked massive protests and led to Republican Gov. Scott Walker's recall election and rise to national prominence.

Thursday's 5-2 ruling is a victory for Walker, who is considering a 2016 run for president and is seeking re-election this year. It also marks the end of the three-year legal fight over the union rights law, which prohibits public worker unions for collectively bargaining for anything beyond base wage increases based on inflation. A federal appeals court twice upheld the law as constitutional.

The high court ruled in a lawsuit filed by the Madison teachers union and a union representing Milwaukee public workers. They had argued that the law, which came to be known as Act 10, violated workers' constitutional rights to free assembly and equal protection.

Walker introduced the proposal shortly after taking office in 2011, a move that was met with fierce resistance from teachers, other public workers and their supporters who flooded the Capitol for weeks in an effort to block the bill's passage. Democratic state senators fled the state for two weeks in a failed attempt to block the bill's passage.

The law bars automatic withdrawals from members' paychecks and requires annual elections to see if members want their unions to go on representing them. It also requires public employees to contribute more toward their health insurance and pension costs, moves that Walker said helped local governments and schools save enough money to deal with other cuts done to balance a state budget shortfall.

Walker's opponent for re-election, Democrat Mary Burke, supports the higher pension and health insurance contributions. But while she supports restoring collective bargaining, Burke has not promised to work for the repeal of Act 10 if elected.

Walker was forced to stand for recall in 2012, a move largely motivated out of anger over the union law. He won, becoming the first governor in U.S. history to defeat a recall.

The union law has been challenged on several fronts since it was introduced, but it's withstood them all.

The state Supreme Court decided to take the case it ruled on Thursday after a Dane County judge sided with the unions and ruled in September 2012 that major portions of the law were unconstitutional.