This undated US government photo shows an aerial view of the National Security Agency in Fort Meade, Md. (AP)

The National Security Agency on Tuesday restarted its bulk collection of Americans’ phone records for a temporary period, following a federal court ruling this week that gave it the green light, U.S. officials said.

The Foreign Intelligence Surveillance Court on Monday ruled that the NSA could resume gathering millions of Americans’ phone metadata — call times, dates and durations — to scan for links to foreign terrorists.

But the resumption is good for only 180 days — or until Nov. 29, in compliance with the USA Freedom Act. That law, which President Obama signed June 2 after a contentious congressional debate, will end the government’s bulk collection of metadata. It provided, however, for a transition period to allow the NSA time to set up an alternative system in which the data is stored by the phone companies.

After the law took effect, the government immediately applied to the surveillance court to restart its collection. Because Congress passed the bill a day after the underlying statute authorizing the NSA program had expired, there was a question as to whether lawmakers had authorized the government’s temporary harvesting of phone records.

“In passing the USA Freedom Act, Congress clearly intended to end bulk data collection of business records and other tangible things,” Judge Michael W. Mosman wrote in his opinion. “But what it took away with one hand, it gave back — for a limited time — with the other. . . . It chose to allow a 180-day transitional period during which such [bulk] collection could continue.”

Sen. Ron Wyden (D-Ore.) said he saw no reason to resume collection, even on a temporary basis. “This illegal dragnet surveillance violated Americans’ rights for 14 years without making our country any safer,” he said.

Mosman also ruled that FreedomWorks, a grass-roots libertarian organization, and its attorney, Ken Cuccinelli II, could submit “friend of the court” briefs that argue against the lawfulness of the metadata program.

In May, a federal appeals court in New York held that the program was unlawful. The U.S. Court of Appeals for the 2nd Circuit ruled that the program stretched the meaning of the statute — Section 215 of the USA Patriot Act — to enable data collection in “staggering” volumes in the chance that “at some future point” there might be a need to search for terrorist links.

Cuccinelli cited the 2nd Circuit opinion, but Mosman said he disagreed with the appeals court. “This description bears little resemblance to how the government actually uses the records,” he said.

The American Civil Liberties Union on Tuesday said it planned to ask the appeals court to block the temporary collection.

The USA Freedom Act amended Section 215 to require that the government use a “specific selection term,” such as a phone number, to request records from the phone companies. It bars the collection of “all call detail records” held by phone companies, as the court had authorized beginning in 2006.

The program began in 2001, under executive authority alone, enabling the NSA to obtain tens of millions of records daily.