WASHINGTON (AP) — The Supreme Court dealt a blow to public sector unions Monday, ruling that thousands of home health care workers in Illinois cannot be required to pay fees that help cover the union’s costs of collective bargaining.

In a 5-4 split along ideological lines, the justices said the practice violates the First Amendment rights of nonmembers who disagree with the positions that unions take.

The ruling is a setback for labor unions that have bolstered their ranks — and bank accounts — in Illinois and other states by signing up hundreds of thousands of in-home care workers. It could lead to an exodus of members who will have little incentive to pay dues if nonmembers don’t have to share the burden of union costs.

But the ruling was limited to this particular segment of workers — not private sector unions — and it stopped short of overturning decades of practice that has generally allowed public sector unions to pass through their representation costs to nonmembers.

Writing for the court, Justice Samuel Alito said home care workers are different from other types of government employees because they work primarily for their disabled or elderly customers and do not have most of the rights and benefits of state employees.

The case involves about 26,000 Illinois workers who provide home care for disabled people and are paid with Medicaid funds administered by the state. In 2003, the state passed a measure deeming the workers state employees eligible for collective bargaining.

A majority of the workers then selected a union to negotiate with the state to increase wages, improve health benefits and set up training programs. Those workers who chose not to join the union had to pay proportional “fair share” fees to cover collective bargaining and other administration costs.

A group of workers led by Pamela Harris — a home health aide who cares for her disabled son at home — filed a lawsuit arguing the fees violate the First Amendment. Backed by the National Right to Work Legal Defense Foundation, the workers said it wasn’t fair to make someone pay fees to a group that takes positions the fee-payer disagrees with.

The workers argue they are not government employees capable of being unionized in the traditional sense. They are different, they say, because they work in people’s homes, not on government property, and are not supervised by other state employees.

The workers had urged the justices to overturn a 1977 Supreme Court decision which held that public employees who choose not to join a union can still be required to pay representation fees, as long as those fees don’t go toward political purposes. They say the union is not merely seeking higher wages, but making a political push for expansion of Medicaid payments.

Alito said the court was not overturning that case, Abood v. Detroit Board of Education. That case, he said, is confined “to full-fledged state employees.”

Justice Elena Kagan wrote the dissent for the four liberal justices. Kagan said the majority’s decision to leave the older case in place is “cause for satisfaction, though hardly applause.”

The state had argued that home health care workers are the same as other public workers because Illinois sets their salaries and any dispute over pay must be worked out with the state. Illinois says it has an interest in bargaining with a single representative as it does with other types of public workers.

A federal district court and the 7th U.S. Circuit Court of Appeals had rejected the lawsuit, citing the high court’s precedent.

Nine other states have allowed home care workers to join unions: California, Connecticut, Maryland, Massachusetts, Minnesota, Missouri, Oregon, Vermont and Washington.