An attempt by Barclays to suppress details of its allegedly massive tax avoidance schemes two years ago ended in farce. The high street bank went to court in the middle of the night to gag the Guardian but was outmanoeuvred by free-spirited souls on the internet.

It showed the legal system struggling to keep documents secret even after they were freely available on the web.

The story emerged in March 2009 when a whistleblower leaked internal Barclays memos to the Liberal Democrat MP Vince Cable.

The memos – passed on to the newspaper – described how a 2007 scheme called Project Knight proposed to save tax by manipulating loans totalling more than $16bn (£9.8bn), through a web of firms in the Cayman Islands, Luxembourg and the United States.

The memos also quoted advice from lawyers on how to blunt any challenges from HM Revenue & Customs. The whistleblower alleged: "It is a commonly held view that no agency in the US or the UK has the resources or the commitment to challenge [Barclays]."

Freshfields, Barclays' lawyers, toiled into the night to compel the Guardian to remove the documents from the website. Geraldine Proudler, a solicitor acting for the Guardian, was woken by a high court judge telephoning at 2am and asked to justify their publication. At 2.31am, Mr Justice Ouseley, over the phone, ordered that the documents be removed from the website, by which time 127 people had read them.

Later that day, Barclays went to court to argue that the documents should be permanently removed, accusing the Guardian of "vigilante journalism" by publishing the documents to "the entire country" rather than merely to regulators.

The Guardian documents disclosed seven tax avoidance schemes operated by Barclays. Many of them were devised by structured capital markets boss Michael Keeley. They involved more than £20bn of loans typically shuttled between entities in Luxembourg and the Caymans, designed to generate hundreds of millions of pounds of tax reliefs, the proceeds frequently shared with US banks..

Alan Rusbridger, the Guardian's editor, told the court that the documents "revealed at first hand the processes involved in structuring extremely complex and artificial tax avoidance vehicles; how lawyers and accountants worked together to exploit loopholes in government legislation; and the degree to which they are sanctioned at the highest levels within Barclays".

At the end of a two-day hearing, Mr Justice Blake ruled that the ban remain, even though the memos were circulating around the web. Anyone could find them within minutes on sites such as WikiLeaks, but he did not accept that all confidentiality had been destroyed.

He also believed that the Guardian was not justified under the Human Rights Act in publishing the unexpurgated documents containing legal advice and other confidential matters.

He specifically ordered the Guardian and other media not to "incite" or even "encourage" their readers to go to other websites to view the documents. Out on the internet, however, members of the public were busy discussing and copying the documents for themselves.

This absurdity was ridiculed a week later by a peer, Matthew Oakeshott, who was then Lib Dem Treasury spokesman. He used parliamentary privilege to tell the public what newspapers could not, when he outlined the case to his fellow peers in the Lords.

It left the Guardian able to report that Oakeshott was advising the public where to find the documents, but still complying with the judge's instruction to prevent the electronic whereabouts of the Barclays documents becoming widely known.