The Supreme Court changed the landscape of online shopping Thursday, freeing state governments to compel retailers beyond their borders to collect sales-tax revenue from consumers and giving a boost to brick-and-mortar stores.

With the boom in Internet commerce increasing exponentially, the court’s 5-to-4 decision could have an impact on millions of Americans almost immediately. For years, avoiding sales tax was a prime perk of online shopping.

States were the big winners at the Supreme Court. They previously were able to require only companies with a physical presence in their states to collect taxes, costing them an estimated $8 billion to $33 billion in uncollected taxes per year.

The losers could be large online retailers that had dodged collecting the taxes — Overstock, Wayfair and Newegg were parties to the suit. Also hit could be small companies that say they are ill equipped to comply with the requirements of more than 10,000 taxing jurisdictions across the country.

“With today’s ruling, all businesses will compete on a level playing field,” said South Dakota Gov. Dennis Daugaard (R), whose state brought the challenge to the Supreme Court.

Major online retailers’ stock prices dropped. The biggest online retailer,, took a small hit, even though it already collects taxes on its sales in all states. The company, whose founder Jeffrey P. Bezos also owns The Washington Post, does not collect taxes on third-party purchases.

President Trump, who has criticized Bezos on Twitter, used the platform to praise the ruling: “Big Supreme Court win on internet sales tax - about time! Big victory for fairness and for our country. Great victory for consumers and retailers.”

Critics of the decision worried about what states will do with their newfound power.

Neil Saunders, managing director of the research firm GlobalData Retail, predicted that consumers could pay as much as $15.2 billion a year in additional taxes. “The challenge for smaller players will be significant, and the concern here is that complexity could stymie innovation and entrepreneurialism,” he said.

Sites such as eBay and Etsy, which serve as a marketplace for individual merchants and small businesses, said that having to collect taxes across the country would put their sellers at a disadvantage.

“More than three quarters of Etsy sellers are businesses of one. They have very different needs and challenges than larger online retailers,” Josh Silverman, the chief executive of Etsy, wrote on the company’s website. “We believe there is now a call to action for Congress to create a simple, fair federal solution for microbusinesses.”

The Trump administration and more than 40 states asked the Supreme Court to overturn its 1992 decision in Quill v. North Dakota, which restricted states from collecting sales tax from retailers without a physical presence in those states. They said a decision in a case involving mail-order catalogues was outdated in an era of e-commerce.

Justice Anthony M. Kennedy, who wrote Thursday’s majority decision, had earlier called for the court to reconsider the decision.

Kennedy wrote that dramatic technological changes had made the court’s previous ruling obsolete and that it unfairly disadvantaged Main Street stores.

“A virtual showroom can show far more inventory, in far more detail, and with greater opportunities for consumer and seller interaction than might be possible for local stores,” Kennedy wrote. “Yet the continuous and pervasive virtual presence of retailers today is, under Quill, simply irrelevant. This Court should not maintain a rule that ignores these substantial virtual connections to the State.”

It is rare for the court to overturn a precedent, especially one that has its roots in a decision more than 50 years old. But Kennedy argued the decision was wrong when it was decided; it was justified on the constitutional mandate that keeps states from raising barriers to interstate commerce.

Kennedy said earlier decisions have become “a judicially created tax shelter” for businesses that intentionally stayed out of states but still wanted to sell goods there. Technology has made that easier, he said.

He was joined by Justices Clarence Thomas, Ruth Bader Ginsburg, Samuel A. Alito Jr. and Neil M. Gorsuch.

Chief Justice John G. Roberts Jr. wrote the dissent. He said the court should not be doing the work of Congress, even if its earlier precedents were wrongly decided.

“E-commerce has grown into a significant and vibrant part of our national economy against the backdrop of established rules, including the physical-presence rule,” he wrote. “Any alteration to those rules with the potential to disrupt the development of such a critical segment of the economy should be undertaken by Congress. The Court should not act on this important question of current economic policy, solely to expiate a mistake it made over 50 years ago.”

Roberts was joined by Justices Stephen G. Breyer, Sonia Sotomayor and Elena Kagan.

The chief justice also said there was no reason for the court to act now, when “the pendulum is swinging in the opposite direction.”

States and local governments already are collecting 80 percent of the tax revenue that would be available if there were no ­physical-presence rule, Roberts said.

Many of the country’s largest online retailers — including Amazon, which accounts for more than 40 percent of the country’s online shopping — already collect sales tax in all 45 states — and the District — where it is required. Walmart and Target are also among the large companies that already collect sales taxes.

South Dakota brought the challenge. It passed a law requiring retailers with more than $100,000 in annual sales or 200 transactions in the state to pay a 4.5 percent tax. Although technically consumers are required to pay sales tax on all purchases, it is practically impossible to collect without the retailer applying it at the point of sale.

Those who argued against overturning Quill said the decision could allow states to go far beyond the model legislation that South Dakota passed, requiring collection by retailers with a single sale in a state or perhaps trying to force the companies to comply retroactively.

Kennedy said that those were issues for another day and that Congress could step in now to deal with them.

The companies that South Dakota had sued because they refused to collect sales taxes were understated in their reactions.

“We welcome the additional clarity provided by the court’s decision today,” said Wayfair spokeswoman Jane Carpenter, who added that the company collects sales tax on 80 percent of its orders.

Nevertheless, shares of Overstock fell more than 7 percent Thursday, while eBay’s stock was down 3 percent. Shares of Wayfair, Amazon and Etsy, meanwhile, all fell between 1 and 2 percent after the decision.

The decision struck some small retailers as deeply worrisome. Colleen Rast, owner of Great Sky Gifts in Kalispell, Mont., said the new rules could amount to tens of thousands in extra costs for her online business, which sells items ranging from $29 jars of caramel sauce to $49 Ralph Lauren T-shirts to $159 snowboarding boots.

“Having to pay taxes in more states would place a huge financial burden on small businesses like mine,” she said. “I am very much worried about my ability to stay in business.”

The case is South Dakota v. Wayfair.