A Wisconsin state Supreme Court race, which could affect the outcome of Republican Gov. Scott Walker's battle with unions, was headed toward a recount Wednesday, with the Democratic-backed candidate leading by a razor-thin margin.

The race, between incumbent Justice David Prosser and Assistant Attorney General JoAnne Kloppenburg, was widely seen as a proxy battle over Mr. Walker and the law he championed that curtails collective-bargaining rights for public-employee unions. The law has divided the state, and has become the...