WASHINGTON — Americans have done more and more of their shopping online in recent years, drawn by the promise of low prices, wide selection and buy-from-home convenience. But e-commerce has also had another edge: Many of those sales were, in effect, tax-free.

The Supreme Court on Thursday moved to close that loophole, ruling that internet retailers can be required to collect sales taxes even in states where they have no physical presence.

The decision, in South Dakota v. Wayfair Inc., was a victory for brick-and-mortar businesses that have long complained they are put at a disadvantage by having to charge sales taxes while many online competitors do not. And it was also a victory for states that have said that they are missing out on tens of billions of dollars in annual revenue.

“State and local governments have really been dealing with a nightmare scenario for several years now,” said Carl Davis, research director at the Institute on Taxation and Economic Policy, a Washington think tank. “This is going to allow state and local governments to improve their tax enforcement and to put local business on a more level playing field.”