WASHINGTON -- A federal judge has directed the government to preserve phone data gathered under a National Security Agency surveillance program beyond a five-year limit.

The order by U.S. District Judge Reggie Walton, who presides over the Foreign Intelligence Surveillance Court, will be in effect while a dispute over preservation of phone data is pending in federal court in the Northern District of California. In the California lawsuits, two private groups challenging the NSA program's legality obtained an order to preserve phone data that may be relevant to the case.

Walton's action temporarily reverses his earlier decision rejecting a Justice Department request to preserve phone data beyond five years, saying that doing so would infringe on privacy interests of U.S. citizens.

Walton noted that the court in California has prohibited the NSA from doing what he had ordered -- destroying data no later than five years from when it was originally produced.

"These conflicting directives from federal courts put the government in an untenable position and are likely to lead to uncertainty and confusion among all concerned" about the status of phone data that was acquired more than five years ago, Walton wrote in a decision Wednesday. He said it appears "unnecessary and probably ill-advised" to put the surveillance court in the position of approving or disapproving steps the government proposes to take in lawsuits.