The decision by the European Court of Justice goes against advice from its advocate general, who said last month that such visas had to be issued under EU law.
The European Court of Justice on Tuesday ruled that EU members are under no obligation to provide humanitarian visas to refugees.
The court ruled on the case of a Syrian family from the Syrian city of Aleppo who applied for a visa to stay with acquaintances in Belgium in October.
"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 in its ruling.
Belgium's immigration minister had said previously that a ruling in favour of humanitarian visas would "throw the gates wide open" to asylum-seekers.
TRT World's Jack Parrock reports from Brussels.
EU Court of Justice rules that EU countries are not obliged to issue visas on humanitarian grounds to refugees pic.twitter.com/KB4iqonT6f— TRT World (@trtworld) March 7, 2017
The court's decision comes as the EU is trying to kerb immigration after taking in some 1.6 million refugees who arrived in Europe across the Mediterranean in 2014-2016.
EU states have struggled to accommodate the influx, ensure security screening and agree on how to share the responsibility for migrants and refugees.
The bloc has also started to arrange treaties with countries south and east of the Mediterranean to 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 criticised 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.