WASHINGTON (Reuters) - The U.S. Supreme Court on Wednesday dealt a big blow to organized labor, ruling that non-members cannot be forced in certain states to pay fees to unions representing public employees such as teachers and police, shutting off a key union revenue source.

The 5-4 ruling overturned a 1977 Supreme Court precedent that had permitted these so-called agency fees, which have been collected from millions of workers who opt not to join unions in lieu of union dues to fund non-political activities such as collective bargaining. The court’s conservative justices were in the majority, with the liberal justices dissenting.

Forcing non-members to pay these fees to unions whose views they may oppose violates their rights to free speech and free association under the U.S. Constitution’s First Amendment, the court said in the ruling authored by Justice Samuel Alito.

“States and public-sector unions may no longer extract agency fees from non-consenting employees,” Alito wrote. In a dissent, Justice Elena Kagan accused the court’s conservatives of “weaponizing the First Amendment” to intervene in economic and regulatory policy.

“This case was nothing more than a blatant political attack to further rig our economy and democracy against everyday Americans in favor of the wealthy and powerful,” public-sector unions including the American Federation of State, County and Municipal Employees (AFSCME), the union directly involved in the case, said in a statement.

Two dozen states had required agency fees. The ruling means that the estimated 5 million non-union workers for state and local governments who have paid them can stop. Agency fees do not involve federal or private-sector employees.

The decision represented a major victory for conservative activists who long have sought to curb the influence of public-sector unions, which often support the Democratic Party and liberal causes.

With the U.S. organized labor movement already in a diminished state compared to past decades, the ruling now deprives unions of a vital revenue stream, undercuts their ability to attract new members and retain current members, and undermines their ability to spend in political races.

Republican President Donald Trump, whose administration backed the challenge to the fees, welcomed the ruling, writing on Twitter, “Big loss for the coffers of the Democrats!”

Unions contend that mandatory agency fees are needed to eliminate the problem of what they call “free riders” - non-members who benefit from union representation, for example through salary and working conditions obtained in collective bargaining - without paying for it.

Unionized teachers, police, firefighters and other civil servants in states without Republican-backed “right-to-work” laws barring agency fees comprise organized labor’s main power base. Public-sector workers are almost six times more likely to belong to a union than those in the private sector.

“Make no mistake, this decision is one of the most significant labor rollbacks we’ve seen in decades,” said Democratic Representative Barbara Lee of California, one of the states that mandated agency fees.

Alito said while the ruling “may cause unions to experience unpleasant transition costs in the short term,” that must be weighed against “how many billions of dollars have been taken from non-members and transferred to public-sector unions in violation of the First Amendment.”

FILE PHOTO: Trees cast shadows outside the U.S. Supreme Court in Washington, U.S., June 25, 2018. REUTERS/Toya Sarno Jordan/File Photo

Alito said the “legal and economic backdrop” has changed since the 1977 ruling in the case Abood vs. Detroit Board of Education that the justices overturned on Wednesday, noting that the rise of unions led to increases in public spending, and subsequently to problems funding employee benefits. This contributed to municipal bankruptcies, Alito added.

Kagan, who read forcefully from her dissenting opinion in the packed courtroom, said the practice of separating union political activities from collective bargaining-related spending, set by the court in Abood ruling, had been a workable solution.

‘NO SUGARCOATING’

“There is no sugarcoating today’s opinion. The majority overthrows a decision entrenched in this nation’s law - and in its economic life - for over 40 years. As a result, it prevents the American people, acting through their state and local officials, from making important choices about workplace governance,” Kagan said.

The decision was issued on the final day of the court’s current term, which began in October.

The justices heard arguments in a similar case in 2016 involving non-union California public school teachers, and appeared poised to overturn the 1977 precedent. But conservative Justice Antonin Scalia’s death weeks later left the court with an even split of conservatives and liberals. Its subsequent 4-4 decision failed to resolve the legal question.

Trump’s appointment of Justice Neil Gorsuch last year restored the court’s conservative majority. Gorsuch’s vote proved to be crucial on Wednesday.

The plaintiff in the case is Mark Janus, a child-support specialist for the state of Illinois who opted not to join AFSCME. A lower court had ruled against Janus, who was backed by anti-union groups, setting up the Supreme Court showdown. Janus had been forced to pay just under $50 a month in agency fees.