Mr. Leers called the ruling “very encouraging.” Coffee shop owners saw it differently.

“There is no way this will hold up,” said John Deckers, a spokesman for the Maastricht coffee shop owners’ association. “It is discrimination against other European Union citizens.”

Image Drug buyers have streamed into Dutch border areas. Credit... The New York Times

If Maastricht gets its way, many other Dutch municipalities will doubtless follow. Last year, two small Dutch towns, Rosendal and Bergen op Zoom, decided to close all their coffee shops after surveys showed that most of their customers were foreigners.

The situation has not made for good neighborly feelings. Many residents of border towns criticize Belgium, France and Germany for tolerating recreational drug use but banning the sale of drugs. “They don’t punish small buyers,” said Cyrille Fijnaut, a professor at the University of Tilburg law school. “But they also don’t have their own coffee shops, so that leaves us as the suppliers. Our policy has been abused, misused, totally perverted.”

As business has boomed, many of the Dutch coffee shops  dingy, hippie establishments in the ’80s and ’90s with a few plastic tubs of marijuana on the shelves  have become slick shops serving freshly squeezed orange juice and coffee in fine china.

The Easy Going Coffee Shop has a computer console at the door where identification documents proving that customers are 18 or older are scanned and recorded. Tiny pictures on driver’s licenses are blown up to life-size on a screen, so guards can get a good look at them. Behind the teller windows, workers still cut the hashish with a big kitchen knife, but all sales are recorded on computerized cash registers.

Mr. Bot’s ruling last month is only an early step in determining whether Maastricht can enforce a Dutch-only policy. A final ruling by the full court is expected by the end of the year.

But Mr. Bot’s finding, a veritable tirade on the evils of drugs, surprised many legal scholars, who expected the European Union’s open market rules to trump any public order arguments, as they have in other cases. Sweden, for instance, which has a long history of struggling with alcohol abuse, was obliged to take down most of its anti-alcohol laws restricting store hours and sales, as they were seen as impinging on free trade.