U.S. District Judge William Pauley issued the decision Friday. He says the program "represents the government's counter-punch" to eliminate al-Qaida's terror network by connecting fragmented and fleeting communications.
In ruling, the judge noted the Sept. 11 terrorist attacks and how the phone data-collection system could have helped investigators connect the dots before the attacks occurred.
He says the government learned from its mistake and "adapted to confront a new enemy: a terror network capable of orchestrating attacks across the world." He said the data-collection program was part of the adjustment.
He dismissed a lawsuit brought by the American Civil Liberties Union. The ACLU did not immediately respond to a message for comment.