MADISON, Wis.—Wisconsin's highest court upheld a law ending most collective-bargaining rights for government employees in the state, a blow for public-sector unions that have been stymied in their efforts to reverse the controversial measure championed by Republican Gov. Scott Walker.

The law, passed in 2011, rocked the state, leading to mass protests and recall elections, while making Mr. Walker a favorite of conservatives across the country. The measure put Wisconsin at the center of a national debate over the role of...