“National security and privacy are not mutually exclusive,” said Senator James Lankford, Republican of Oklahoma, a freshman who like several other younger Republicans voted against the senior senator from his state. “They can both be accomplished through responsible intelligence gathering and careful respect for the freedoms of law-abiding Americans.”

Tuesday’s vote was a rebuke to Senator Mitch McConnell, Republican of Kentucky and the majority leader, who, until the end in a bitter floor speech, maintained the bill was a dangerous diminishment of national security. Lawmakers in both parties beat back amendments — one by one — that he insisted were necessary to blunt some of the bill’s controls on government spying.

Mr. McConnell blasted his fellow senators — and by association Speaker John A. Boehner, who heartily endorsed the measure — as taking “one more tool away from those who defend our country every day.”

“This is a significant weakening of the tools that were put in place in the wake of 9/11 to protect the country,” he said. “I think Congress is misreading the public mood if they think Americans are concerned about the privacy implications.”

But even scores of senators who loathed the actions of Mr. Snowden voted for the legislation.

The legislation’s goals are twofold: to rein in aspects of the government’s data collection authority and to crack open the workings of the secret national security court that oversees it. After six months, the phone companies, not the N.S.A., will hold the bulk phone records — logs of calls placed from one number to another, and the time and the duration of those contacts, but not the content of what was said. A new kind of court order will permit the government to swiftly analyze them.

The Foreign Intelligence Surveillance Court, for the first time, will be required to declassify some of its most significant decisions, and outside voices will be allowed to argue for privacy rights before the court in certain cases.