The "sweetheart" deal between HM Revenue and Customs and the investment bank Goldman Sachs was flawed, but not illegal, the High Court has ruled.
Dave Hartnett, the former head of tax at HMRC, should not have taken into account "the potential embarrassment" to the Chancellor, George Osborne, if the settlement worth up to £20m did not go through, the judge said, but no law was broken.
Mr Justice Nicol said the 2010 deal was "not a glorious episode in the history of the Revenue" and criticised officials for not being briefed by lawyers or getting "approval" for the deal, but he said "maladministration and illegality" were separate issues.
The judge's ruling came as a disappointment to the anti-tax-avoidance group UK Uncut, whose legal offshoot had applied for judicial review, arguing HMRC's failing involved illegality and breach of statutory duty.
But Jim Harra, HMRC's director-general for business tax, welcomed the decision. He said: "The High Court's comprehensive dismissal of UK Uncut's claim puts to rest the fallacy that HMRC is soft on large businesses."
Anna Walker, campaigns director of UK Uncut Legal Action, said: "Obviously, while we are deeply disappointed that this deal has not been declared unlawful, the judge's ruling that top HMRC officials played politics with major tax deals to protect Osborne's reputation is a major victory in exposing the truth behind these secret deals."