The ECJ said the two airlines had obtained state aid after the Irish government introduced a controversial air travel tax in 2009, at the height of the financial crisis.
The government said airlines would pay €2 per passenger on short-haul flights operated from Dublin, but €10 on long-haul flights.
The ECJ concluded that the €8 differential constituted illegal state aid, and must be paid by the airlines to the government.
Ryanair said it now faced a bill of €12m as a result of the ECJ judgment, while Aer Lingus estimated it would have to pay €4m.
The two airlines said they would pursue the Irish government for damages incurred in having to pay what they said was an “illegal” tax.
Ryanair said: “This ruling now clears the way for Ryanair (and other airlines) to pursue our High Court action against the Irish government to recover the €88m of damages we suffered as a result of being forced to pay this illegal tax.”
Aer Lingus, owned by International Airlines Group, said it was studying the ECJ judgment and that it was seeking “substantial damages” from the Irish government “for losses flowing from the infringement of EU rules on free movement of services arising from the air travel tax”.
Ryanair and Aer Lingus opposed the introduction of the tax, arguing that it damaged the travel sector and hurt their businesses.
The tax was introduced seven years ago as Ireland faced a financial crunch following the collapse of much of its banking sector.
The ECJ said Ryanair and Aer Lingus benefited from the two-tier travel tax, and rejected the airlines’ claims that it was now too late to recoup the €8 differential.