Barclays Bank obtained a court order early today banning the Guardian from publishing documents which showed how the bank set up companies to avoid hundreds of millions of pounds in tax.

The gagging order was granted by Mr Justice Ouseley after Barclays complained about seven documents on the Guardian's website which had been leaked to the Liberal Democrats' deputy leader, Vince Cable.

The internal Barclays memos – leaked by a Barclays whistleblower – showed executives from SCM, Barclays's structured capital markets division, seeking approval for a 2007 plan to sink more than $16bn (£11.4bn) into US loans.

Tax benefits were to be generated by an elaborate circuit of Cayman islands companies, US partnerships and Luxembourg subsidiaries.

The documents had been leaked to Cable by a former employee of the bank, who wrote a long account of how the bank works.

The anonymous whistleblower wrote to Cable: "The last year has seen the global taxpayer having to rescue the global financial system. The taxpayer has already had a gun put to their head and been told to pay up or watch the financial system and life as we know it disappear into a black hole.

"It is a commonly held view that no agency in the US or the UK has the resources or the commitment to challenge SCM. SCM has huge amounts of resources, the best minds rewarded by millions of pounds. Compare this with HMRC [Her Majesty's Revenue & Customs] recently advertising for a tax and accounting expert with the pay at £45,000.

"Through the use of lawyers and client confidentiality SCM regularly circumvents these rules, just one example of why HMRC will never, in its current state, be up to the job of combating this business."

The Guardian's decision to publish the documents came on a day when the chancellor, Alistair Darling, told parliament he had asked HMRC to publish shortly a draft code of practice on taxation for banks "so that banks will comply not just with the letter of the law but the spirit of the law".

Barclays's lawyers, Freshfields, worked into the early hours to force the Guardian to remove the documents from the website. They argued that the documents were the property of Barclays and could only have been leaked by someone who acquired them wrongfully and in breach of confidentiality agreements.

The Guardian's solicitor, Geraldine Proudler, was woken by the judge at 2am and asked to argue the Guardian's case by telephone. Around 2.31am, Mr Justice Ouseley issued an order for the documents to be removed from the Guardian's website.

Cable said it was both "incongruous" and "offensive" that banks that rely on state support should avoid paying tax and therefore be "selling the taxpayer short". Although the taxpayer has not had to directly support Barclays by taking an equity stake, the bank had relied on the government's special liquidity scheme to provide funding for loans.

"The banks are able to organise their activities in such a way that they can run rings around the Inland Revenue," he told the Telegraph. "It serves no other purpose than to reduce tax. The fundamental point is that it is incongruous and offensive that banks which are either directly or indirectly dependent on the government should be systematically finding ways to avoid tax."

Cable, who passed the documents to HMRC and the Financial Services Authority, told the Sunday Times this week: "The documents suggest a deeply ingrained culture of tax avoidance. The Barclays team looks like the spider at the centre of a highly artificial web of non-transparent transactions through tax havens. Reputable banks don't turn tax avoidance into a profit machine."

A Guardian spokesman said this morning that the paper would appeal against the order. "Tax avoidance is a matter of high public and political interest. These documents showed for the first time how major banks set up artificial schemes with the aim of earning hundreds of millions in tax-free money, which is why the Barclays whistleblower leaked them.

"All decisions about tax are taken in secret, hidden from public view. It is not right for a judge to prevent daylight from shining on the few documents ever to have emerged which graphically demonstrate what HMRC is up against."