A fuel tax that Spain imposed in 2002 was illegal, Europe’s highest court ruled on Thursday, clearing the way for consumers to claim back billions of euros and potentially knock Madrid’s deficit-reduction programme off track.

The tax on fuel including petrol, diesel, heavy fuel oil and kerosene ran from Jan. 1 2002 to Jan. 1 2013.

The Court of Justice of the European Union (ECJ) in Luxembourg said it had been incompatible with the EU Excise Duty Directive because it did not have a specific purpose that must not be purely budgetary, such as an environmental aim.

Proceeds from the tax, set up to finance healthcare in Spain’s autonomous regions, were about 13 billion euros ($17.8 billion).

“We note that the implementation of this tax was made after consultation with the European Commission ... who authorised the Spanish government and its regions,” Treasury Minister Cristobal Montoro told reporters, adding that some of the responsibility should be shared.

He said the financial impact could not be calculated.

Consumers will have to provide receipts of purchase, meaning the government will almost certainly not have to pay back the whole sum.

But some companies will have records. Catalan haulage company Transportes Jordi Besora SL, which brought the case to court, paid fuel duty of more than 45,000 euros for the years 2005-2008.

“I’m extremely satisfied by this ruling and hope to be able to eventually receive the money,” said Jordi Besora, head of the company.

Madrid asked for back payments on the tax to be limited and said a payout in full would jeopardise public health spending.

But Thursday’s ruling - which Spain cannot appeal against - found it was inappropriate to “limit the temporal effects of this judgment” because, in maintaining the tax for more than a decade, the Spanish authorities did not act in good faith.

Spain must cut its budget gap to 5.8 percent of GDP - or around 60 billion euros - this year and to 4.2 percent of GDP in 2015, to ensure it drops below 3 percent in 2016 as requested by EU finance ministers last June.