If Walmart paid it on time, and waited to get a refund through the usual channels, it would most likely never see the money again, he added.

Puerto Rico is expected to go through a court-supervised debt restructuring soon, and any request for a tax refund from Walmart would almost certainly get lost in the crowd of bondholders, labor unions, lawyers and others jockeying to recover their money.

Walmart expressed satisfaction with the decision. “Today’s ruling is a victory not only for Walmart Puerto Rico but also for our customers, our more than 14,000 Puerto Rican associates, and the many Puerto Rican suppliers and farmers who depend so heavily on us,” Lorenzo Lopez, a spokesman, said.

The company did not explicitly threaten to leave Puerto Rico if it did not prevail, but it did argue in court that no business could operate for long in a place that confiscated all of its profit.

Walmart, based in Bentonville, Ark., is Puerto Rico’s largest employer outside the government, operating 48 large, busy stores under several names. People joke that since Walmart’s arrival on the island in 1992, they no longer have to go anywhere else, because they can eat all their meals and buy everything they need there.