Its name may be synonymous with European unity ‑ but increasingly its coffee shops are not.

Moves by the Dutch border town of Maastricht to ban foreigners from its marijuana cafes have been upheld by the European court, in a rare contravention of EU laws governing free markets and free movement of people.

In response to what it terms an influx of hordes of weed-seeking tourists, mainly from Belgium and France, Maastricht decided to limit admission to coffee shops to Dutch residents only. Every day, some 4,000 tourists in search of the perfect smoke enter Maastricht, according to the major of the town. Some 70% of the town's coffee-shop customers come from across the border.

Marc Josemans, owner and chairman of the Association of Official Maastricht Coffee Shops, brought a legal challenge before the Dutch council of state, arguing that a ban contravenes European legislation on free movement and free trade in goods and services within the EU. The council asked the European court of justice for its interpretation of EU law, which it will then employ in its ruling expected at the end of this year.

In his finding, the EU court's advocate general, Yve Bot, said that narcotics do not count as regular goods because they are against the law. "Narcotics, including cannabis, are not goods like others and their sale does not benefit from the freedoms of movement guaranteed by European Union law, inasmuch as their sale is unlawful," he said.

He did add however that in cases of their medical or scientific use, marijuana does "come under internal market rules".

The court said that Maastricht was right to view drug tourism as "a genuine and sufficiently serious threat to public order", and thus the restriction of foreigners from coffee shops "constitutes a measure necessary to protect the residents of the municipality from trouble".

The finding concluded by saying that backpackers descending upon the Netherlands for a weekend of exuberance and oblivion endangered the European Union's security. "Drug tourism, in so far as it conceals, in actual fact, international trade in narcotics and fuels organised criminal activities, threatens even the European Union's internal security," it said.