The federal judge who first declared the National Security Agency’s bulk telephone metadata collection program likely unconstitutional and “almost Orwellian” has ordered the agency to cease collecting phone records, weeks before the program is set to expire and a new one will take its place.

“The fact remains that the indiscriminate, daily bulk collection, long-term retention, and analysis of telephony metadata almost certainly violates a person’s reasonable expectation of privacy,” United States D.C. District Court Judge Richard Leon wrote in a Monday ruling.

Leon repeated the assertion he made in 2013 that the program “likely violates the Constitution” and ordered the signals intelligence agency to immediately halt the collection of metadata belonging to plaintiffs in the case.

“[B]ecause the loss of constitutional freedoms for even one day is a significant harm,” the judge concluded.

RELATED: D.C. District Judge Now ‘Last Hope of the American People’ to Shut Down NSA Phone Program

The D.C. Circuit judge handed down a preliminary injunction against the collection of anti-surveillance lawyer Larry Klayman and his plaintiffs’ data in December 2013, months after documents leaked by former NSA contractor Edward Snowden revealed NSA was likely collecting virtually all Americans’ landline telephone records.

Leon stayed the motion to give the government, citing national security concerns, time to mount an appeal. The subsequent appeals process took almost two years — far longer than expected as a result of the government dragging its feet, the judge intimated earlier this fall — before an appeals court sent the case back down to Leon in August.

The appeals court said Klayman couldn’t prove NSA targeted Verizon Wireless customers including Klayman and his plaintiffs. In September Klayman asked Leon to add attorney J.J. Little and his firm to the suit, citing a Snowden document showing the FBI, on behalf of NSA, ordering Verizon Business Network Services to hand over three months of call records — including the time, duration, location, phone and dialed numbers of American callers.

Little and his firm were customers of Verizon Business Network Services at the time the order was sent, and were allowed to join with Klayman to challenge the NSA’s collection as an unreasonable search and seizure in violation of the Fourth Amendment.

RELATED: Federal Judge May Lift Stay on Injunction Against NSA Phone Program

In the interim the U.S. Second Circuit Court of Appeals ruled the program illegal but declined to shut it down, and Congress passed the USA Freedom Act in May, scrapping the program after a 180-day transition period to a new, narrower program legislators say will better safeguard Americans’ privacy.

Leon said Congress’ six-month window “failed to pass constitutional muster … Because ‘[i]t has long been established that the loss of constitutional freedoms, “for even minimal periods of time, unquestionably constitutes irreparable injury,”‘” Leon wrote, quoting previous legal precedents.

“[T]he Little plaintiffs have adequately demonstrated irreparable injury,” he continued. “As such, it makes no difference that this violation now has a foreseeable end.”

As a result the judge ordered the NSA to discontinue collecting records belonging to Little and his firm, but left Klayman and his other plaintiffs, Charles Strange and Mary Ann Strange, out of the order, despite the likelihood theirs and others’ records were collected.

Leon supported his ruling with several factors related to law enforcement “special need” scenarios, which require citizens sacrifice certain rights in exchange for security, such as in airports, where travelers willingly surrender certain privacy rights over their belonging to ensure nothing harmful is brought onboard an aircraft.

The judge recognized the government’s need to ensure security in such instances, but added Americans are not willingly opening their phones to scrutiny simply by virtue of having and using them. He further pointed out metadata has the potential to reveal even more intimate details of a person’s life by establishing an easily viewable pattern of who they call, when and where, even if the content of such calls goes unsurveilled.

“To be sure, the very purpose of the Fourth Amendment would be undermined were this court to defer to Congress’s determination that individual liberty should be sacrificed to better combat today’s evil,” Leon wrote.

The judge further added the government has yet to prove the program prevents threats in the first place.

“To date, the government has still not cited a single instance in which telephone metadata analysis has stopped an imminent attack, or otherwise aided the government in achieving any time-sensitive objective,” he wrote. “In sum, despite changes to the program, the government is still, in effect, asking this court to sanction a dragnet of unparalleled  proportions.”

Snowden himself celebrated the judge’s ruling on Twitter.

“In historic decision, U.S. court finds [NSA] spying violated Americans’ rights,” the whistleblower tweeted Monday. “Victory!”

Though privacy and civil liberties groups triumphantly touted the judge’s ruling, Leon himself said the issue of domestic surveillance is far from concluded.

“With the government’s authority to operate the bulk telephony metadata program quickly coming to an end, this case is perhaps the last chapter in the judiciary’s evaluation of this particular program’s compatibility with the Constitution,” he wrote. “It will not, however, be the last chapter in the ongoing struggle to balance privacy rights and national security interests under our Constitution in an age of evolving technological wizardry.”

National security lawyer Bradley Moss, associate counsel at the law firm of Mark Zaid, agreed.

“Judge Leon’s ruling remains in the minority among the various courts to have addressed the constitutional question of the legality of the NSA surveillance programs,” Moss told InsideSources Tuesday. “Virtually all other district court judges have deferred to the Supreme Court’s ruling in Smith v. Maryland, although several have implicitly requested that the Supreme Court revisit the Smith ruling in order to provide updated guidance in light of changes in technology.”

In the 1979 Supreme Court case Smith v. Maryland, the court ruled the use of a pen register device — which records all number called from a particular phone line — did not violate the Fourth Amendment, since telephone companies keep such records anyway.

“Although the USA Freedom Act will go into effect in a few weeks and alleviate the Second Circuit’s concerns regarding statutory authority, the overarching Fourth Amendment question remains unresolved and will most likely continue onward for some time by way of the various pending cases,” Moss said. “It remains likely – although not a certainty by any stretch – that the issue will eventually require resolution by the Supreme Court.

The NSA’s new program is ready to replace the bulk telephony metadata program when it expires on Nov. 29, according to an agency memo sent to Congress Monday.

“While our work is not yet complete, testing of internal systems functionality at both NSA and the telecommunications providers has begun, and exchanges of test files with the providers are under way,” the memo, obtained by Reuters, read, adding the agency “has successfully developed a technical architecture to support the new program”

National Security Agency Director Mike Rogers warned Congress earlier this fall the new program will be a slower and less effective means of preventing imminent terrorist threats.

Follow Giuseppe on Twitter