WASHINGTON -- In a setback for organized labor that could have been much worse, the Supreme Court ruled on Monday that certain government-funded employees cannot be required to pay fees to the public sector unions that represent them, a decision that could hurt some unions financially.

The 5-4 ruling in Harris v. Quinn, written by Justice Samuel Alito for the majority, was not the worst-case scenario that unions had feared. But it does deliver a blow to major unions that have organized Medicaid-funded home care workers and other workers who aren't "full-fledged public employees" in the majority's eyes.

Such workers, the court ruled, cannot be compelled to pay "agency fees." Because unions have to represent all the employees in a particular bargaining unit, they commonly seek requirements in their contracts that all workers, whether union members or not, pay agency fees to help cover the administrative costs of bargaining. This avoids what unions commonly refer to as "freeloading" by non-union employees.

Demanding an agency fee of the Illinois home care workers who sued the state in Harris v. Quinn would run afoul of the First Amendment, Alito wrote.

"If we accepted Illinois' argument, we would approve an unprecedented violation of the bedrock principle that, except perhaps in the rarest of circumstances, no person in this country may be compelled to subsidize speech by a third party that he or she does not wish to support," Alito wrote, referring to the union.

And yet the majority did not issue the sweeping decision that had the potential to devastate organized labor at large. Anti-union interests, including the National Right to Work Legal Defense Foundation, which represented the Harris plaintiffs, had hoped the court would apply its decision on agency fees to all public sector workers in the U.S., essentially overturning an earlier Supreme Court case, Abood v. Detroit Board of Education.

With far-reaching implications for an already embattled labor movement, such a ruling would have instituted a kind of right-to-work principle on the public sector, giving workers throughout the country the ability to opt out of supporting the union.

The court did not go so far. Alito wrote that the majority believed Abood did not apply to the workers in question, declaring them not public employees in the traditional sense. The Illinois home care workers may be funded in large part by state Medicaid payments, but they ultimately answer to individual private sector clients, the majority determined.

But by giving certain workers the ability to opt out of fees, the ruling will likely hurt unions such as the Service Employees International Union, which represented the workers in the Harris case, as well as the American Federation of State, County and Municipal Employees, which has also organized similar workers. Home care workers and personal assistants, who care for the elderly and disabled in their homes, have helped grow the ranks of some unions in recent years.

In a statement immediately following the ruling, the SEIU argued that the decision would hurt both workers and their clients.

"The ruling places at risk a system of consumer-directed home care in Illinois that has proven successful in raising wages, providing affordable health care benefits, and increasing training," the union said. "States need to build a stable, qualified workforce to meet the growing need for home care -- and having a strong union for home care workers is the only approach that has proven effective."