Updated

The Obama administration moved on two fronts Friday to preserve the National Security Agency's controversial spy programs, appealing a major ruling against the agency while winning permission from a secretive court to continue collecting Americans' phone records.

The request to keep collecting phone records was made to the Foreign Intelligence Surveillance Court. These requests are made periodically -- and have been made public ever since the NSA controversy erupted last summer -- but this would be the first since two conflicting court decisions about the program's legality. The FISA court approved the request.

The Justice Department on Friday also appealed the ruling of a federal judge who, in a major rebuke for the administration, said the National Security Agency's data collection likely violates the Constitution. In its brief court filing, the department said it was appealing to the U.S. Court of Appeals for the District of Columbia.

The appeal follows the ruling from U.S. District Court Judge Richard Leon. The ruling last month was the first major legal defeat for the NSA since a cascade of leaks from ex-contractor Edward Snowden began shedding light on once-secret corners of the agency's expansive surveillance and data collection programs.

Leon called the program "almost-Orwellian technology" and challenged its constitutionality.

"I cannot imagine a more 'indiscriminate' and 'arbitrary invasion' than this systematic and high-tech collection and retention of personal data on virtually every single citizen for purposes of querying and analyzing it without prior judicial approval," he wrote. "Surely such a program infringes on 'that degree of privacy' that the founders enshrined in the Fourth Amendment. Indeed I have little doubt that the author of our Constitution, James Madison, who cautioned us to beware 'the abridgement of freedom of the people by gradual and silent encroachments by those in power,' would be aghast."

Leon granted the injunction sought by plaintiffs Larry Klayman and Charles Strange, concluding they were likely to prevail in their constitutional challenge. Leon, an appointee of former President George W. Bush, ruled that the two men are likely to be able to show that their privacy interests outweigh the government's interest in collecting the data. Leon says that means the massive collection program is an unreasonable search under the Constitution's Fourth Amendment. However, he also stayed his decision "pending appeal," giving the U.S. government time to fight the decision over the next several months.

Despite that ruling, another federal judge days later ruled in favor of the NSA program.

U.S. District Judge William H. Pauley III concluded the program was a necessary extension of steps taken after the Sept. 11 terrorist attacks.

"This blunt tool only works because it collects everything," Pauley said. "The collection is broad, but the scope of counterterrorism investigations is unprecedented."

The conflicting rulings could set the stage for a Supreme Court battle over the NSA.

The Associated Press contributed to this report.