Updated

A federal appeals court ruled on Wednesday that a National Security Agency program that collected the metadata from billions of phone calls made by Americans was illegal and possibly unconstitutional despite upholding the conviction of four Somali immigrants charged in a terror-fundraising case in which the information was used.

While the unanimous ruling by a three-judge panel of the 9th Circuit Court of Appeals said that the information collected by the NSA’s telephone metadata program was so minor that it did not affect the convictions of the Somalis, the court’s opinion stated that the "bulk collection" of the data violated the Foreign Intelligence Surveillance Act.

The case being heard by the court involved Basaaly Moalin and three other men, who were found guilty by a San Diego jury in 2013 on charges of fundraising for the terror group Al-Shabaab.

FORMER NSA CONTRACTOR PLEADS GUILTY IN THEFT OF CLASSIFIED DOCUMENTS

"Here the NSA collected Moalin’s (and millions of other Americans’) telephony metadata on an ongoing, daily basis for years," Judge Marsha Berzon wrote in her opinion. "Moalin likely had a reasonable expectation of privacy in his telephony metadata — at the very least, it is a close question."

The 9th Circuit Court took up the case federal appeals court in New York in 2015 had ruled the mass surveillance of phone calls was illegal. The Supreme Court may soon take up this legal and constitutional question.

The NSA’s phone call tracking without authorization began under President George W. Bush following the 9/11 terror attacks. Another similar one was approved by the secretive FISA Court in 2006 – and renewed a number of times since – but the appeals court ruled that those rulings were legally flawed.

The NSA last year reportedly recommended that the White House abandon the controversial surveillance program, claiming the legal and logistical burdens of maintaining it outweigh its benefits to the intelligence community.

CLICK HERE TO GET THE FOX NEWS APP

The recommendation, which was first reported by The Wall Street Journal and involved input from NSA, the FBI and the Department of Justice, appears to represent an about-face regarding a program – long criticized by privacy advocates – that federal officials previously said was vital to finding and disrupting terrorist plots against the United States.

Terrorists have largely abandoned using cell phones and landlines for communication, opting instead for encrypted apps and social media platforms, a separate intelligence source familiar with the topic told Fox News.

Fox News' Christopher Carbone contributed to this report.