The court dismissed a complaint by Hungary and Slovakia who objected to the September 2015 emergency measure to relocate 120,000 asylum seekers from where they had arrived in Greece and Italy to most of the other 28 EU member states.
Sweden backed the agreement and has also pushed for a new asylum system to see refugees distributed more evenly throughout the EU's member states.
Cecilia Wikström, a Swedish member of the European Parliament as well as the Parliament's rapporteur on a future European system for asylum seekers, welcomed the decision. She says the ruling is "crystal clear".
"This is a temporary measure necessary to respond effectively and swiftly to an emergency situation with an influx of displaced people," Wikström tells Radio Sweden. "It encourages me and others who believe in the European project to build an asylum policy for the European Union that is resilient over time and that functions irrespectively of where the influx is."
Wikström says the relocation of the 120,000 is underway, albeit slowly, even with the legal challenge by Hungary and Slovakia. She says almost 30,000 have already been resettled in the bloc.