The UK Supreme Court has ruled a "contrived" scheme used by Deutsche Bank and UBS to allow the banks and their bankers to escape £135m (€174m) in tax on bonuses was unlawful.

The arrangement, which dated back to 2004, involved bankers receiving bonuses in the form of shares in specially created companies, rather than cash, the UK's tax authority, Her Majesty's Revenue and Customs (HMRC), said today.

By making the bonus awards in this way, the banks hoped their employees would avoid making national insurance payments and benefit from an income tax break in a way which the Supreme Court said parliament had not intended it to be used.

"This is an important victory and confirmation from the UK's highest court that tax avoidance is simply unacceptable," junior finance minister David Gauke said in a statement.

"The UK is home to some of the world's most successful banks and we have been clear we expect them and their employees to pay their fair share of tax," he added.

Revelations about how some very wealthy individuals and major corporations pay little tax on vast earnings – often legally – has sparked public anger in recent years, putting pressure on the government and on HMRC, which politicians frequently say is too lenient on both tax evaders and avoiders.

A spokesman for Deutche Bank said it noted the decision and that all tax and national insurance relating to the scheme had already been paid.

UBS said it was disappointed by the ruling.

"This matter concerns a disagreement over the interpretation of highly technical tax legislation and dates back to a one-off compensation plan for 2003," a spokesman said.