The fees remain the responsibility of the client.

Spanish banks averted huge tax bills when the country's Supreme Court on Tuesday scrapped its own earlier ruling calling on lenders to pay fees on mortgages which they had been passing on to their clients for years.

The court in Madrid ruled that these fees remain the responsibility of the client, Spanish news site elpais.com reported, citing justice department spokesmen.

Ratings agency Moody's had estimated in March that a retroactive tax bill for the mortgage fees in question could cost Spain's banking sector at least 4 billion euros (4.58 billion dollars.)

The consumer protection organization for bank customers, Asufin, had estimated that the banking sector could even face total claims of more than 30 billion euros.

The Supreme Court reached Tuesday's decision after two days of deliberations.

The court said it had reviewed its earlier decision due to its "far-reaching social and economic ramifications."

Left-wing parties and consumer organizations criticized the decision as a "scandal."