The Supreme Court ruled Wednesday that government workers can't be forced to contribute to labor unions that represent them in collective bargaining, dealing a serious financial blow to organized labor.

The court's conservative majority scrapped a 41-year-old decision that had allowed states to require that public employees pay some fees to unions that represent them, even if the workers choose not to join.

The 5-4 decision fulfills a longtime wish of conservatives to get rid of the so-called fair share fees that non-members pay to unions in roughly two dozen states. Organized labor is a key Democratic constituency.

The court ruled that the laws violate the First Amendment by compelling workers to support unions they may disagree with.

"States and public-sector unions may no longer extract agency fees from nonconsenting employees," Justice Samuel Alito said in his majority opinion in the latest case in which Justice Neil Gorsuch, an appointee of President Donald Trump, provided a key fifth vote for a conservative outcome.

Trump himself tweeted his approval of the decision while Alito still was reading a summary of it from the bench.

"Big loss for the coffers of the Democrats!" Trump said in the tweet.

In dissent, Justice Elena Kagan wrote of the big impact of the decision. "There is no sugarcoating today's opinion. The majority overthrows a decision entrenched in this Nation's law - and 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. And it does so by weaponizing the First Amendment, in a way that unleashes judges, now and in the future, to intervene in economic and regulatory policy."

The court's three other liberal justices joined the dissent.

The court split 4-4 the last time it considered the issue in 2016 following the death of Justice Antonin Scalia. Last year, unions strongly opposed Gorsuch's nomination by Trump.

The unions say the outcome could affect more than 5 million government workers in about two dozen states and the District of Columbia.

The case involving Illinois state government worker Mark Janus is similar to the one the justices took up in 2016. At that time, the court appeared to be ready to overrule a 1977 high court decision that serves as the legal foundation for the fair share fees. But Scalia's death left the court tied, and a lower court ruling in favor of the fees remained in place.

The unions argued that so-called fair share fees pay for collective bargaining and other work the union does on behalf of all employees, not just its members. More than half the states already have right-to-work laws banning mandatory fees, but most members of public-employee unions are concentrated in states that don't, including California, New York and Illinois.

Labor leaders fear that not only will workers who don't belong to a union stop paying fees, but that some union members might decide to stop paying dues if they could in essence get the union's representation for free.

A recent study by Frank Manzo of the Illinois Public Policy Institute and Robert Bruno of the University of Illinois at Urbana-Champaign estimated that public-sector unions could lose more than 700,000 members over time as a result of the ruling and that unions also could suffer a loss of political influence that could depress wages as well.

Alito acknowledged that unions could "experience unpleasant transition costs in the short term." But he said labor's problems pale in comparison to "the considerable windfall that unions have received...for the past 41 years."

Billions of dollars have been taken from workers who were not union members in that time, he said.

Kagan, reading a summary of her dissent in the courtroom, said unions only could collect money for the costs of negotiating terms of employment. "But no part of those fees could go to any of the union's political or ideological activities," she said.

The court's majority said public-sector unions aren't entitled to any money from employees without their consent.