The ruling puts new pressure on Senator Mitch McConnell of Kentucky, the majority leader, to make serious changes to the Patriot Act, which he has so far aggressively defended against any alteration, even as recently as Thursday on the Senate floor. Mr. McConnell has pressed to maintain the N.S.A.’s existing program against bipartisan efforts to scale it back, and has proposed simply extending the statute by the June 1 deadline.

But the court’s ruling calls into question whether that statute can still be used to issue new orders to phone companies requiring them to turn over their customers’ records.

Thursday’s ruling is the first time a higher-level court in the regular judicial system has reviewed the N.S.A. phone records program. It did not come with any injunction ordering the program to cease, and it is not clear that anything else will happen in the judicial system before Congress has to make a decision about the expiring law.

The data collection had repeatedly been approved in secret by judges serving on the Foreign Intelligence Surveillance Court, known as the FISA court, which oversees national security surveillance. Those judges, who hear arguments only from the government, were willing to accept an interpretation of Section 215 that the appeals court rejected on Thursday.

The court, in a unanimous ruling written by Judge Gerard E. Lynch, held that Section 215 “cannot bear the weight the government asks us to assign to it, and that it does not authorize the telephone metadata program.” It declared the program illegal, saying, “We do so comfortably in the full understanding that if Congress chooses to authorize such a far-reaching and unprecedented program, it has every opportunity to do so, and to do so unambiguously.”