Overcrowding cannot be used as a reason to impound search and rescue ships, the European Court of Justice (ECJ) said in a ruling on Monday.
The judgment came after two Sea Watch ships were subject to inspection in Italy in the summer of 2020.
The humanitarian organisation's vessels were impounded on the grounds that they were "not certified in respect of search and rescue activities at sea" and had taken more people on board than they "were authorised to accommodate".
The ECJ ruling on Monday said that people on board due to a rescue operation cannot be taken into account when port authorities verify if safety rules were complied with.
"The number of persons on board, even if greater than that which is authorised, cannot, therefore, in itself, constitute a ground for a control," the court press release said.
Once migrants have disembarked, the ECJ said, national port authorities could subject a ship to an inspection but had to demonstrate that there were "serious indications of a danger to health, safety, on-board working conditions or the environment".
The ECJ added that ships certified as cargo ships are often used for search and rescue activities. The Sea Watch ships in question, for instance, were classified as cargo ships under the German flag.
The court said that port authorities did not have the power to "demand proof that those ships hold certificates other than those issued by the flag State or that they comply with all the requirements applicable to another classification."
German NGO Sea Watch called the ruling a "clear win for sea rescue".
The organisation said their ships had been detained due to "absurd reasons" including a missing "imaginary certification" and "too many rescued people were on board."
"Italy can't demand an imaginary certification that doesn't even exist under the German flag. Also, the number of rescued persons isn't a reason for detention," Sea Watch International tweeted.
"The ruling provides clear legal security for NGOs and is a victory for sea rescue."