Guardian editors on Tuesday revealed why and how the newspaper destroyed computer hard drives containing copies of some of the secret files leaked by Edward Snowden.

The decision was taken after a threat of legal action by the government that could have stopped reporting on the extent of American and British government surveillance revealed by the documents.

It resulted in one of the stranger episodes in the history of digital-age journalism. On Saturday 20 July, in a deserted basement of the Guardian's King's Cross offices, a senior editor and a Guardian computer expert used angle grinders and other tools to pulverise the hard drives and memory chips on which the encrypted files had been stored.

As they worked they were watched by technicians from Government Communications Headquarters (GCHQ) who took notes and photographs, but who left empty-handed.

The editor of the Guardian, Alan Rusbridger, had earlier informed government officials that other copies of the files existed outside the country and that the Guardian was neither the sole recipient nor steward of the files leaked by Snowden, a former National Security Agency (NSA) contractor. But the government insisted that the material be either destroyed or surrendered.

Twelve days after the destruction of the files the Guardian reported on US funding of GCHQ eavesdropping operations and published a portrait of working life in the British agency's huge "doughnut" building in Cheltenham. Guardian US, based and edited in New York, has also continued to report on evidence of NSA co-operation with US telecommunications corporations to maximise the collection of data on internet and phone users around the world.

The British government has attempted to step up its pressure on journalists, with the detention in Heathrow on Sunday of David Miranda, the partner of Glenn Greenwald, who has led the Guardian's US reporting on the files.

Miranda was detained for nine hours under a section of legislation enacted in 2000 aimed at terrorists. The use of this measure – which applies only to airports and ports – meant the normal protection for suspects in the UK, including journalists, did not apply.

The initial UK attempts to stop reporting on the files came two weeks after the publication of the first story based on Snowden's leaks, about a secret US court order obliging the communications corporation Verizon to hand over data on its customers' phone usage. This was followed by a story detailing how GCHQ was making use of data collected by the NSA's internet monitoring programme, Prism.

The remains of a computer that held files leaked by Edward Snowden to the Guardian and destroyed at the behest of the UK government. Photograph: Roger Tooth

Days later the paper published another story revealing how UK intelligence spied on British allies at two London summits.

Shortly afterwards two senior British officials arrived at the Guardian's offices to see Rusbridger and his deputy, Paul Johnson. They were cordial but made it clear they came on high authority to demand the immediate surrender of all the Snowden files in the Guardian's possession.

They argued that the material was stolen and that a newspaper had no business holding on to it. The Official Secrets Act was mentioned but not threatened. At this stage officials emphasised they preferred a low-key route rather than go to court.

The Guardian editors argued that there was a substantial public interest in the hitherto unknown scale of government surveillance and the collaboration with technology and telecoms companies, particularly given the apparent weakness of parliamentary and judicial oversight.

There was no written threat of any legal moves.

After three weeks which saw the publication of several more articles on both sides of the Atlantic about GCHQ and NSA internet and phone surveillance, British government officials got back in touch and took a sterner approach.

"You've had your fun. Now we want the stuff back," one of them said.

The same two senior officials who had visited the Guardian the previous month returned with the message that patience with the newspaper's reporting was wearing out.

They expressed fears that foreign governments, in particular Russia or China, could hack into the Guardian's IT network. But the Guardian explained the security surrounding the documents, which were held in isolation and not stored on any Guardian system.

However, in a subsequent meeting, an intelligence agency expert argued that the material was still vulnerable. He said by way of example that if there was a plastic cup in the room where the work was being carried out foreign agents could train a laser on it to pick up the vibrations of what was being said. Vibrations on windows could similarly be monitored remotely by laser.

Between 16 and 19 July government pressure intensified and, in a series of phone calls and meetings, the threat of legal action or even a police raid became more explicit.

At one point the Guardian was told: "We are giving active consideration to the legal route."

Rusbridger said: "I don't know what changed or why it changed. I imagine there were different conversations going on within the security apparatus, within Whitehall and within Downing Street."

The Guardian's lawyers believed the government might either seek an injunction under the law of confidence, a catch-all statute that covers any unauthorised possession of confidential material, or start criminal proceedings under the Official Secrets Act.

Either brought with it the risk that the Guardian's reporting would be frozen everywhere and that the newspaper would be forced to hand over material.

"I explained to British authorities that there were other copies in America and Brazil so they wouldn't be achieving anything," Rusbridger said. "But once it was obvious that they would be going to law I preferred to destroy our copy rather than hand it back to them or allow the courts to freeze our reporting."

Any such surrender would have represented a betrayal of the source, Edward Snowden, Rusbridger believed. The files could ultimately have been used in the American whistleblower's prosecution.

"I don't think we had Snowden's consent to hand the material back, and I didn't want to help the UK authorities to know what he had given us," the Guardian editor said.

Furthermore the computer records could be analysed forensically to yield information on which journalists had seen and worked with which files.

Rusbridger took the decision that if the government was determined to stop UK-based reporting on the Snowden files, the best option was destroy the London copy and to continue to edit and report from America and Brazil. Journalists in America are protected by the first amendment, guaranteeing free speech.

Since a legal case over the publication of the Pentagon Papers by the Washington Post and New York Times in 1971, it is widely considered that the US state would not succeed in attempting prior restraint on publication. The leaked Pentagon Papers revealed top secret details of the poor progress of the US military campaign in Vietnam.

Talks began with government officials on a procedure that might satisfy their need to ensure the material had been destroyed, but which would at the same time protect the Guardian's sources and its journalism.

The compromise ultimately brought Paul Johnson, Guardian News and Media's executive director Sheila Fitzsimons, and one of its top computer experts, David Blishen, to the basement of its Kings Place office on a hot Saturday morning to meet two GCHQ officials with notebooks and cameras.

The intelligence men stood over Johnson and Blishen as they went to work on the hard drives and memory chips with angle grinders and drills, pointing out the critical points on circuit boards to attack. They took pictures as the debris was swept up but took nothing away.

It was a unique encounter in the long and uneasy relationship between the press and the intelligence agencies, and a highly unusual, very physical, compromise between the demands of national security and free expression.

But it was largely a symbolic act. Both sides were well aware that other copies existed outside the UK and that the reporting on the reach of state surveillance in the 21st century would continue.

"It affects every citizen, but journalists I think should be aware of the difficulties they are going to face in the future because everybody in 2013 leaves a very big digital trail that is very easily accessed," Rusbridger said.

"I hope what [the Miranda detention row] will do is to send people back to read the stories that so upset the British state because there has been a lot of reporting about what GCHQ and the NSA are up to. What Snowden is trying to do is draw attention to the degree to which we are on a road to total surveillance."