Updated

A federal judge ruled Monday that the National Security Agency's bulk collection of phone records likely violates the Constitution, in a major setback for the controversial spy agency.

U.S. District Court Judge Richard Leon granted a preliminary injunction sought by plaintiffs Larry Klayman and Charles Strange. However, he also stayed his decision "pending appeal," giving the U.S. government time to fight the decision over the next several months.

The judge wrote that he expects the government to "prepare itself to comply with this order when, and if, it is upheld."

Even after the appeals court rules, the Supreme Court will probably have the last word.

The ruling was the first major legal defeat for the NSA since former contractor Edward Snowden began exposing secrets about the NSA's data collection over the summer.

More On This...

    "We've seen the opinion and are studying it," the Justice Department said in a brief statement after the decision. "We believe the program is constitutional as previous judges have found. We have no further comment at this time."

    Snowden himself released a statement late Monday saying, "I acted on my belief that the NSA's mass surveillance programs would not withstand a constitutional challenge, and that the American public deserved a chance to see these issues determined by open courts.

    " Today, a secret program authorized by a secret court was, when exposed to the light of day, found to violate Americans' rights. It is the first of many."

    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.

    "The Fourth Amendment typically requires 'a neutral and detached authority be interposed between the police and the public,' and it is offended by 'general warrants' and laws that allow searches to be conducted 'indiscriminately and without regard to their connections with a crime under investigation,'" he wrote.

    He added: "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. 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 went on to call the program "almost-Orwellian technology."

    The Obama administration has defended the program as a crucial tool against terrorism.

    But in his a 68-page, heavily footnoted opinion, Leon concluded that the government didn't cite a single instance in which the program "actually stopped an imminent terrorist attack."

    "I have serious doubts about the efficacy of the metadata collection program as a means of conducting time-sensitive investigations in cases involving imminent threats of terrorism," he added.

    He entered an order to bar the government from collecting "any telephony metadata associated with their personal Verizon accounts" and requiring the government to "destroy any such metadata in its possession" collected through the program.

    He said was staying his ruling pending appeal "in light of the significant national security interests at stake in this case and the novelty of the constitutional issues."

    Fox News' Jake Gibson and The Associated Press contributed to this report.