WASHINGTON (Reuters) - States may force online retailers to collect potentially billions of dollars in sales taxes, the U.S. Supreme Court said in a major ruling on Thursday that undercut an advantage many e-commerce companies have enjoyed over brick-and-mortar rivals.

In a 5-4 ruling reviving a South Dakota law challenged by Wayfair Inc, Overstock.com Inc and Newegg Inc, the justices overturned a 1992 high court precedent that had barred states from requiring businesses with no “physical presence” there, like out-of-state online retailers, to collect sales taxes.

Shares of online retailers fell following the ruling, which opened the door to a new revenue stream to fill state coffers - up to $13 billion annually, according to a federal report.

“Big Supreme Court win on internet sales tax - about time!” President Donald Trump, who has bashed online retail powerhouse Amazon.com Inc and whose administration backed South Dakota, said on Twitter. “Big victory for fairness and for our country. Great victory for consumers and retailers.”

The ruling likely will result in many consumers paying more for online purchases. Because many e-commerce companies do not collect state sales taxes on purchases, they have had an advantage over brick-and-mortar businesses that do collect it.

South Dakota’s law, enacted in 2016, focused on larger out-of-state e-commerce companies, requiring them to collect sales tax if they amass $100,000 in sales or 200 separate transactions. Other states are now expected to pursue sales tax on out-of-state online purchases, with more legal fights likely. Forty-five of the 50 states have sales taxes.

Overstock closed down 7.2 percent and Wayfair dropped 1.6 percent, though both said the ruling would have no major impact on their businesses. Amazon shares closed down 1.1 percent.

Amazon, which was not involved in the Supreme Court case, collects sales taxes on direct purchases from its site but does not typically collect taxes for merchandise sold on its platform by third-party vendors, representing about half of total sales. The ruling means states may now seek to tax more of those sales, Moody’s analyst Charlie O’Shea said.

Trump has blasted Amazon CEO Jeff Bezos, who also owns the Washington Post, a newspaper that the Republican president has disparaged for its coverage of him.

Liberal Ruth Bader Ginsburg joined four conservative justices in the majority in the ruling authored by Justice Anthony Kennedy, while conservative Chief Justice John Roberts joined the court’s three other liberals in dissent.

“Rejecting the physical presence rule is necessary to ensure that artificial competitive advantages are not created by this court’s precedents,” Kennedy said.

In the digital era, the costs of complying with different tax regimes “are largely unrelated to whether a company happens to have a physical presence in a state,” Kennedy wrote.

‘DEFEND MAIN STREET’

“This is a great day for South Dakota. We have long fought the battle to defend Main Street businesses and now with today’s ruling, all businesses will compete on a level playing field,” South Dakota Republican Governor Dennis Daugaard said.

Roberts, in dissent, said e-commerce has exploded in the United States in part because there have been uniform rules.

“Any alteration of those rules with the potential to disrupt the development of such a critical segment of the economy should be undertaken by Congress,” Roberts added.

Democratic U.S. Senator Heidi Heitkamp of North Dakota was on the losing side in 1992 when she was that state’s tax commissioner in the ruling that was overturned on Thursday. Heitkamp suggested that states follow South Dakota’s lead and enact laws tailored not to target small businesses.

U.S. Supreme Court is seen in Washington, U.S. April 24, 2018. REUTERS/Yuri Gripas

“It’s important that you look at what the court said about it not being a blank check for the states. That should be a message to the states,” Heitkamp told Reuters.

Shares of eBay Inc and Etsy Inc, which both provide platforms for small retailers to sell their wares, were off 3.2 percent and 1.4 percent, respectively.

Shares of major retailers that have a sizeable presence online as well operating brick-and-mortar stores responded positively. Target Corp closed up 1 percent and Walmart Inc was up 0.7 percent.

The South Dakota law and others like it could yet face legal challenges on other grounds. Congress could also intervene to set a nationwide standard.

“You will certainly see, absent congressional action, significant litigation, as states try to push the envelope on this,” said Mike Dabbs, senior director of government relations at eBay, which had backed Wayfair.

Jeffrey LeSage, Americas vice chairman for tax at accounting firm KPMG, said the ruling “could turn out to be almost as significant for American businesses as the recent rewrite of the U.S. federal tax code.”

The win was welcomed by groups representing brick-and-mortar retailers and decried by e-commerce advocates.

The ruling puts an end to a legal regime that “distorts free markets and puts local brick and mortar stores at a competitive disadvantage with their online-only counterparts,” said Deborah White, general counsel of the Retail Industry Leaders’ Association.

On the other hand, small internet businesses will lose out because of the increased compliance costs, said Chris Cox, a lawyer for e-commerce industry group NetChoice.