BRUSSELS (AP) -- The European Union's top court ruled on Thursday that Volkswagen breached the law by installing on its cars a so-called defeat device to cheat on emission tests and cannot argue it was merely protecting car engines.

The scandal known as "Dieselgate" erupted five years ago when the U.S. Environmental Protection Agency found that Volkswagen had installed special software to rig U.S. emissions tests for its latest "clean diesel" vehicles.

The German car manufacturer admitted to fitting millions of cars with the device and it turned out that the use of the cheating software had not been isolated to the U.S. In Europe, it had argued that the software could be justified by the fact that it helps protect the engine over time.

Volkswagen was referred to as "company X" in the court ruling, which established that "a manufacturer cannot install a defeat device which systematically improves, during approval procedures, the performance of the vehicle emission control system and thus obtain approval of the vehicle."

The case was examined by the ECJ after the Paris prosecutor's office opened a judicial investigation into whether Volkswagen deceived buyers of diesel cars fitted with the device.

"This landmark ruling is good news for getting cleaner air in Europe," said Jens Muller, the air quality coordinator at Transport & Environment, an umbrella group of NGOs campaigning for cleaner transport. "National authorities can't allow carmakers to prioritize profits over our health anymore. Now there are no more excuses: Manipulated cars must be fixed and consumers must be compensated across Europe."

In its detailed and technical ruling, the court dismissed the idea that the presence of the device could be justified by the fact it contributes to preventing the ageing or clogging up of the engine.

"In order to be justified, the presence of such a device must allow the engine to be protected against sudden and exceptional damage, and that only those immediate risks of damage which give rise to a specific hazard when the vehicle is driven are such as to justify the use of a defeat device," the court said.

In a separate ruling this summer, the ECJ said that EU consumers can sue in the country where they bought Volkswagen vehicles fitted with the device rather than having it to do it in Germany, making it easier for them to start legal action.

Volkswagen admitted that about 11 million diesel vehicles worldwide were fitted with the deceptive software, which reduced nitrogen oxide emissions when the cars were placed on a test machine but allowed higher emissions and improved engine performance during normal driving. The scandal cost Volkswagen $35 billion in fines and civil settlements and led to the recall of millions of vehicles.

Volkswagen said the ECJ ruling won't have consequences on the ongoing legal disputes notably because the court did not comment on the question of possible damages to car owners.