BRUSSELS (Reuters) - European Union states do not have to admit people on humanitarian grounds, even if they are at risk of torture or inhuman treatment, the EU’s top court ruled on Tuesday, cutting off a possible channel for asylum seekers into the bloc.

The decision by the European Court of Justice (ECJ) goes against advice from its advocate general, who said last month that such visas had to be issued under EU law.

It spares EU states a new big headache at a time when they are pushing to stem immigration by cutting off asylum seekers and labor migrants alike after taking in some 1.6 million people arriving across the Mediterranean in 2014-2016.

The court ruled on the case of a Syrian family from the city of Aleppo who applied for a visa to stay with acquaintances in Belgium in October. Belgian authorities had refused the visa, leading to a court battle.

“Member States are not required, under EU law, to grant a humanitarian visa to persons who wish to enter their territory with a view to applying for asylum, but they remain free to do so on the basis of their national law,” the court said.

While EU member states can now issue such visas if they choose, an EU-wide legal obligation to do so would have paved the way for many new applications they would then have been unable to reject.

Some European lawmakers, as well as aid groups, have called for such a solution, saying EU embassies and consulates outside of the bloc should handle such requests.

“NGOs (non-governmental organizations) wanted to move the EU border to the embassies but the ECJ has reined them in. A good thing,” said Belgium’s migration minister, Theo Francken.

EU states have struggled to accommodate the migrants and refugees who made it into the bloc, ensure sufficient security screening and agree between themselves on how to share out the responsibility.

They have waged bitter political battles over that for some two years now, with no sign of agreement emerging on the horizon.

The bloc has hence increasingly started to turn to countries south and east of the Mediterranean to have them block people on their way to Europe and be able to send them back more easily.

“Had the court ruled otherwise, it would have been a huge, a massive problem,” said a diplomat in Brussels who is involved in EU migration policies.

Other politicians and NGOs criticized the verdict, saying it ignored the EU’s commitments to human rights and continued to put refugees in harm’s way.

“Today’s verdict is a sad day for the protection of refugees and a day of celebration for fortress builders and human traffickers,” said Karl Kopp of Pro Asyl, a German rights group.