A federal judge has ordered the government to stop destroying National Security Agency surveillance records that could be used to challenge the legality of its spying programs in court.

U.S. District Court Judge Jeffrey White’s ruling came at the request of the Electronic Frontier Foundation, which is in the midst of a case challenging NSA’s ability to surveil foreign citizen’s U.S.-based email and social media accounts.

According to the EFF, the signals intelligence agency and the Department of Justice were knowingly destroying key evidence in the case by purposefully misinterpreting earlier preservation orders by multiple courts, multiple times.

In February, the DOJ asked the Foreign Intelligence Surveillance Court to keep metadata beyond the five-year retention limit to address pending lawsuits from organizations like EFF and the American Civil Liberties Union, which alleged NSA illegally surveilled their clients.

According to multiple accounts, the DOJ made a purposefully flawed case for keeping such records, fully expecting FISA Court Judge Reggie Walton to forbid such retention. He did, which allowed the DOJ to tell plaintiffs that the evidence of their surveillance had to be destroyed.

A California district court trying EFF’s case then asked the DOJ in March to inform the FISA Court about its case, and preserve surveillance data collected under both White House and FISA authority as evidence. That order was ignored, forcing the EFF to file a temporary restraining order to halt the data’s destruction, and appeal the case to the FISA Court.

Justice Department attorneys subsequently told FISA Court Judge Reggie Walton that they did not receive a request to keep metadata collected under FISA authority as well as executive authority (despite documents proving otherwise). After reviewing the case and correspondence between EFF, the California court and DOJ, Walton ruled against the department, accused it of attempting to deliberately mislead the court, and ordered a stay on the records’ destruction.

Earlier this week Justice Department lawyers informed organizations pursuing cases against NSA that metadata gathered under FISA authority was still being destroyed, despite the March order. The Electronic Frontier Foundation immediately filed an emergency temporary restraining order with Judge White, who moments later issued an order telling the government, again, to stop.

“Defendants are ordered not to destroy any documents that may be relevant to the claims at issue in this action, including the [FISA] Section 702 materials,” White wrote.

The DOJ was furthered ordered to file an immediate response justifying its actions. It responded with a statement claiming it did not interpret the prior restraining order to include Internet content interceptions, and that the department was under the impression the court was still trying to determine if the order applied to such evidence.

The DOJ further requested that the judge issue a temporary stay on his order, and that failing to do so would “cause severe operational consequences.”

“It is not credible that, as the government contends, simply refusing to destroy during the next 18 hours the communications it has intercepted will cause ‘the possible suspension of the Section 702 program,'” the EFF said in a statement late Thursday. “How can the preservation of these intercepted communications cause a ‘loss of access to lawfully collected signals intelligence information’? That information will remain accessible even though it is being preserved.”

The EFF alleged the government’s claim that it “never understood before this afternoon” the court’s intention to preserve all data was difficult to believe.

“This, too, lacks any credibility, especially in light of the extensive discussions between Court and counsel at the March 19, 2014 hearing on the evidence preservation dispute,” the statement reads. “The government’s disregard for the past three months of its obligations under the court’s [temporary restraining order] should not be retroactively blessed by granting a stay that permits the government to continue destroying evidence.”

Follow Giuseppe on Twitter and Facebook.