The "sweetheart" tax deal between HM Revenue and Customs and Goldman Sachs was procedurally flawed but not unlawful, the High Court ruled today.

JA judge listed a number of HMRC failings, including Dave Hartnett, then permanent secretary for tax, wrongly taking into account "the potential embarrassment" to Chancellor George Osborne if the settlement worth up to £20 million did not go through.

Mr Hartnett initially shook hands on the deal on November 19, 2010 following a long-running dispute with Goldman Sachs over National Insurance contribution payments dating back to the 1990s.

Download the new Independent Premium app Sharing the full story, not just the headlines

Mr Justice Nicol, sitting in London, said it was "not a glorious episode in the history of the Revenue".

But he ruled case law showed that "maladministration and illegality" were separate issues, and allowing the deal to go ahead was not itself unlawful.

Tax authority lawyers defended the settlement, saying it was among five big business deals declared "reasonable" by a 2012 report of the National Audit Office (NAO) .

The judge's ruling came as "a disappointment" to campaign group UK Uncut Legal Action who had applied for judicial review, arguing HMRC's list of failings involved illegality and a breach of statutory duty.

The group complained that an "aggressive" bank had been "rewarded" for several years of failing to pay tax it owed, causing "real disquiet among the taxpaying public".

Murray Worthy, a director of the group, said he was disappointed, but added: "This case has shown that the Government's tough talk on tax is just that - talk not substance."

Jim Harra, HMRC's director-general for business tax, disagreed and said: "The High Court's comprehensive dismissal of UK Uncut's claim puts to rest the fallacy that HMRC is soft on large businesses."

Daily coronavirus briefing No hype, just the advice and analysis you need Enter your email address Continue Continue Please enter an email address Email address is invalid Fill out this field Email address is invalid Email already exists. Log in to update your newsletter preferences Register with your social account or click here to log in I would like to receive morning headlines Monday - Friday plus breaking news alerts by email Update newsletter preferences

"HMRC has an exemplary record in relentlessly challenging those who avoid tax. We have recovered £34 billion in additional revenues from large businesses in the last seven years.

"The High Court's judgment confirms what HMRC has always said: that while we made errors in settling the Goldman Sachs dispute, we made the right settlement in the circumstances, and that our decision was both proper and lawful.

"This issue has been rigorously and repeatedly scrutinised - by the Public Accounts Committee, by a retired High Court judge on behalf of the National Audit Office and now by the High Court itself."

UK Uncut says it is wrong to allow rich companies to avoid paying millions in tax while the Government imposes tough austerity measures on the poor and ordinary taxpayers are pursued for every penny.

Group lawyers put before the court an email and a witness statement showing that Mr Hartnett overruled legal advice, the HMRC's own guidelines and its internal review board to ensure the deal went ahead.

Just over a week after the handshake, the Revenue's high-risk corporate management board attempted to block the deal, just as the Chancellor announced that the top 15 banks in the country had signed up to a new code of conduct related to tax.

An email from Mr Hartnett on December 7, 2010 described how Goldman Sachs allegedly "went off the deep end" after the board decision and threatened to withdraw from the Government's bank code of practice, first published in December 2009.

The email warned: "The risks here are major embarrassment to the ChX (Chancellor of the Exchequer), HMRC, the LBS (the large business service of the HMRC), you and me, not least if GS withdraw from the code."

The witness statement from Mr Hartnett, who retired as head of tax last summer following strong criticism of the Goldman Sachs deal from the public accounts committee, said the bank withdrawing from the code "would have embarrassed the Chancellor".

The deal was eventually approved and the November 19 decision endorsed by Mr Hartnett and another tax commissioner, Melanie Dawes, HMRC's director general for business tax, on December 9 2010.

In his judgment, the judge said Mr Hartnett had wrongly taken into account "the potential embarrassment to the Chancellor of the Exchequer if Goldman Sachs were to withdraw from the tax code".

The judge said: "HMRC accepts that was an irrelevant consideration and should not have featured in his decision-making process."

The amount lost to the Revenue through the deal is not known but is at least £5 million to £10million, and the Commons Public Accounts Committee has received evidence that it could be up to £20 million.

HMRC said in a press statement: "Large business tax settlements are a vital part of how HMRC secures tax revenues for the country and without them Britain's public finances would be seriously damaged."

Solicitor Rosa Curling, of law firm Leigh Day, which represented UK Uncut Legal Action, said: "This is a disappointing decision but it has been an extremely important case to fight. It has forced HMRC to reveal the process by which it reached a deal with Goldman Sachs, a settlement which let the bank off an estimated £20 million tax owed.

"Without this legal action HMRC would have succeeded in keeping secret the fact that the settlement was in part motivated by saving the blushes of the Chancellor rather than collecting the tax due to the public purse.

"We hope through this litigation that HMRC has learnt from its mistakes in the past and will ensure that such sweetheart deals, like that reached with Goldman Sachs, do not happen in the future."

PA