A U.S. appeals court has reversed a ruling that said the National Security Agency's program to collect phone records from millions of Americans in an effort to locate terrorist plots was illegal.

In 2013, a lower court ruled the program was probably unconstitutional because it likely violates the Constitution's ban on unreasonable searches.

The appellate court, however, ruled the plaintiffs failed to show they were targeted for surveillance as part of the program. The three-judge panel sent the case back to a lower court judge who had issued an injunction, pending the appeal, to halt the data collection.

The plaintiffs consisted of an activist and the father of an NSA employee killed in Afghanistan.

In June, the U.S. Congress passed a law aimed at scaling back the surveillance program and ending most bulk collection of Americans' phone records. The law was passed soon after the program was suspended following a U.S. appeals court ruling that the U.S. Patriot Act never authorized the NSA to collect such data.

The Foreign Intelligence Surveillance Court, a special judicial body that oversees the NSA program, later ruled the program can resume for 180 days. The six-month period was designed to give the NSA time to set up an alternative system in which the phone companies store the data.

The agency's powers have come under scrutiny since former contractor Edward Snowden leaked details of the surveillance program to the news media in 2013.