While Senate approval of the bill has been widely expected, the outcome of Tuesday’s vote was not certain because several lawmakers — including Senators Ron Wyden, Democrat of Oregon, and Rand Paul, Republican of Kentucky — had vowed to filibuster the legislation, meaning the approval of 60 of the 100 senators was necessary to overcome that procedural delay tactic.

The vote was close, and was held open longer than expected at a 58-to-38 split while the holdouts fell under heavy lobbying by their colleagues. Ultimately, two more senators — John Kennedy, Republican of Louisiana, and Claire McCaskill, Democrat of Missouri — voted for the legislation, getting to the 60-vote threshold.

The vote was also closely watched because civil liberties-minded liberals have been pressuring Democrats to oppose the surveillance extension without the sort of changes the House rejected last week. Such pressure suggests that the vote could have political reverberations if progressive-leaning voters treat it as a litmus test in future contests like the 2020 Democratic presidential primaries.

First enacted in 2008, the law codified a form of the N.S.A. warrantless surveillance program that the Bush administration secretly created after the Sept. 11 attacks. In 2012, Congress extended it for five years without changes. It is now up for renewal for the first time since the 2013 leaks by the former intelligence contractor Edward J. Snowden set off a broad debate about surveillance and privacy.

Before the vote, Mr. Wyden and Mr. Paul held a news conference with several other senators who argued that the bill as written was insufficient and who objected to a maneuver by the Senate majority leader, Mitch McConnell, Republican of Kentucky, to prevent lawmakers from getting a chance to vote on amendments to it.