WASHINGTON -- The five Republican-nominated members of the U.S. Supreme Court on Wednesday overturned 40 years of precedent and dealt a blow to public employee unions in New Jersey and elsewhere, which primarily support Democrats.

The Supreme Court ruled, 5-4, that public unions could not collect fees from employees who choose not to pay dues, even though the unions still must represent them and the workers still benefit from the wages and benefits obtained in negotiations.

"We conclude that this arrangement violates the free speech rights of nonmembers by compelling them to subsidize private speech on matters of substantial public concern," Justice Samuel Alito wrote for the court.

The ruling will likely reverberate through New Jersey, which has one of the highest rates of union membership. Along with about two dozen other states, workers here are required to join their union or participate in fair-share arrangements, where they pay only the portion of annual dues that supports the union's nonpartisan activities.

AFL-CIO New Jersey President Charles Wowkanech said Wednesday the ruling will weaken the U.S. labor movement and "deprive workers from having a voice at work through their unions."

And Marie Blistan, president of the New Jersey Education Association, the largest public union in the Garden State, called the ruling "blatantly anti-worker" and "anti-middle class."

In anticipation of the decision, Gov. Phil Murphy last month signed the Workplace Democracy Enhancement Act, which gave the state's public employee unions greater access to members and penalized employers that encouraged people to leave their bargaining units.

On Wednesday, Murphy, a Democrat, lamented the expected ruling as a "dark day" for organized labor.

"In so many respects, folks in the country walked through the union door to the middle class," he said at an unrelated event in Newark.

Justices ruled in 1977 in Abood vs. Detroit Board of Education that unions could charge employees so-called "agency fees" to cover the costs of representation, but not require them to pay full dues since some of that money could go to back political candidates that a particular worker might not support.

Unions have to represent everyone under their jurisdiction, including non-members. Agency fees, which cannot exceed 85 percent of dues, go for nonpolitical activities such as contract negotiations or grievance hearings.

The decision came as no surprise; justices appeared to be ready to overturn Abood before the 2016 death of Justice Antonin Scalia created a 4-4 split on the court.

Groups trying to weaken the political power of organized labor found their latest case when Mark Janus, who works at the Illinois Department of Healthcare and Family Services, claimed that paying agency fees violated his First Amendment rights because there was no way to separate the political and non-political activities of unions.

Groups funded by energy executives Charles and David Koch, whose own ability to spend millions of dollars on political campaigns in opposition to union-backed candidates was enhanced by the Supreme Court in its Citizens United decision, praised the ruling as a restoration of public workers' First Amendment rights.

"Today is a game-changer for New Jersey and the trajectory of the country," Americans for Prosperity's Garden State director, Erica Jedynak said in a statement. "A victory for worker freedom, public employees will no longer be forced to pay union dues as a condition of employment or fund political speech against their will."

Public sector unions spent almost $65 million on the 2016 campaign, 90 percent in support of Democrats, according to the Center for Responsive Politics, a Washington-based research group.

NJ Advance Media staff writer Brent Johnson contributed to this report.

Jonathan D. Salant may be reached at jsalant@njadvancemedia.com. Follow him on Twitter @JDSalant or on Facebook. Find NJ.com Politics on Facebook.

Samantha Marcus may be reached at smarcus@njadvancemedia.com. Follow her on Twitter @samanthamarcus. Find NJ.com Politics on Facebook.