The U.S. Supreme Court ruled Wednesday that states may prevent judicial candidates from personally asking for campaign contributions.

The high court determined that such laws do not violate the First Amendment’s free speech protections. Thirty of the 39 states that hold elections for judges also ban them from asking for campaign contributions directly.

“Judges are not politicians, even when they come to the bench by way of the ballot. And a state’s decision to elect its judiciary does not compel it to treat judicial candidates like campaigners for political office,” wrote Chief Justice John Roberts, a conservative who sided with the court’s liberal members in the case.

The 5-4 decision comes as a relief -- and a surprise -- to lawyers’ groups and progressive organizations, who feared that the court would continue to chip away at ethical rules written to try to insulate judicial candidates from the political process.

Bert Brandenburg, executive director of Justice at Stake, said the decision “helps the public, by reassuring them that they will not find themselves in court before a judge who has received a check directly from the opposing party in their case.”

But the decision does not remove judicial candidates from campaign fundraising completely. Candidates running for judge typically leave the task of asking for money to supporters and friends. Most affected states still allow candidates to know the identity of their donors and send thank-you notes.

Four of the high court’s conservative justices dissented from the ruling.

“One cannot have judicial elections without judicial campaigns, and judicial campaigns without funds for campaigning, and funds for campaigning without asking for them,” wrote Justice Antonin Scalia.

A major point of contention was whether states could come up with less strict rules that would still protect the integrity of the court system and of judges, because laws that restrict free speech must be narrowly tailored. Roberts called many of the alternatives “unworkable.”

Opponents of the bans suggested, for example, that states could ban only one-on-one solicitations, or only in-person requests. But Roberts said asking for money in mass mailings to lawyers, or through text messages, would not be much better.

Neither would a rule requiring judges to recuse themselves from cases involving lawyers or litigants who donated to the judge’s campaign. That kind of ban “would disable many jurisdictions,” Roberts wrote. In fact, he added, savvy litigants could even donate to judicial campaigns just to make sure they certain judges wouldn’t be able to hear their case.

Scalia, though, argued that the existing bans were so broad, they barred activities that would have no effect on how the public views judges’ integrity.

A candidate “may not call up an old friend, a cousin or even her parents to ask for a donation to her campaign. The state has not come up with a plausible explanation of how soliciting someone who has no chance of appearing in the candidate’s court will diminish public confidence in judges,” Scalia wrote.

The case before the Supreme Court comes from Florida, where in 2009 a county judicial candidate named Lanell Williams-Yulee was fined nearly $1,900 for signing her name to a fundraising letter. The Florida Supreme Court upheld the restriction in Yulee’s case, but the issue had split lower courts. Federal appeals courts in four states -- Arizona, Georgia, Kentucky and Minnesota -- struck down the rules prior to the high court’s decision.