In the end, the Senate cried, “Uncle!”

Faced with the indefinite loss of surveillance powers that the White House swears keep Americans safe from terrorists, U.S. senators rebuked the body’s majority leader Tuesday. Instead, they sided with their colleagues in the House of Representatives, as well as President Obama, in passing a bill that will keep much of the Patriot Act intact, but also enact the first significant changes to surveillance programs since the 9/11 attacks.

The Senate’s vote capped a tense standoff that saw key portions of the Patriot Act expire Monday and two of the body’s most prominent members, presidential candidate Rand Paul and Majority Leader Mitch McConnell, come out the big losers. The National Security Agency, meanwhile, the very organization that the bill was meant to curb, can arguably chalk up a win.

Paul, who used fillibuster-style tactics to force the Patriot Act to expire this week, may have emerged as the undisputed standard bearer of the libertarian wing of his party, but he’s now public enemy No. 1 with the majority of his fellow Republicans, who blame him for backing them into a corner over national secuirty policy, their traditional political stronghold.

Paul stood down his campaign against the bill, the USA Freedom Act, early Tuesday, resigned to its inevitable passage.

Paul had proposed two amendments to the bill: one that would prevent the intelligence community from querying entire corporations for records rather than specific individuals; and another barring “parallel construction,” a law enforcement technique that involves pursuing an investigation while hiding the secretive means by which an original tip was found. His colleagues weren’t in the mood to play ball: his tweaks weren’t considered.

As tension rose Tuesday morning, The Daily Beast asked Paul if he planned any final parliamentary moves to block the bill. “No, I think we’re about done,” he said.

McConnell then led his own effort to tweak the bill with measures that its supporters said would just water it down. He too got the cold shoulder, as every one of his amendments were easily voted down Tuesday afternoon.

Supporters of the Freedom Act hailed it as an important ratcheting back of intrusive government spying. But it was difficult to call the vote a resounding victory for civil libertarians and privacy activists, who have fought largely in vain for a decade and a half to curb the surveillance state.

“It’s an historic moment,” Senator Patrick Leahy, the Vermont Democrat who was both an architect of the Patriot Act and the Freedom Act, said in remarks on the Senate floor moments after the vote. “It’s the first major overhaul of government surveillance in decades and adds significant privacy protections for the American people.”

And that’s true. The Freedom Act will put an end to the NSA’s collection of Americans’ phone records, which was first revealed in leaks by ex-NSA contractor Edward Snowden in 2013. It will also inject new transparency measures into the secretive process by which the government obtains court orders to monitor the communications of Americans and foreigners.

But the legislation was also quietly embraced by NSA officials, who said it largely preserved their authorities while ditching a program that was never all that useful.

The phone records program is the only one that the agency has lost in the two years since the Snowden leaks began, an outcome that current and former officials have told The Daily Beast is better than just about any they could have imagined. The phone records program was rarely used. And under the Freedom Act, the agency will still have access to not only the same set of data, but potentially more, because the original NSA program didn’t collect information about cellphone calls.

The phone records will be stored with phone companies, and not the NSA, which officials have said isn’t an ideal solution. But it’s one they can live with, and considering it’s the only program they’ve had to give up, the NSA arguably dodged a bullet.

McConnell’s proposed amendments would have slowed the process of shifting the phone records program from the NSA to the phone companies and stripped the bill of some of its most significant transparency provisions—in particular a requirement that the Foreign Intelligence Surveillance Court, which meets in secret to issue surveillance orders, publish some of its rulings.

Civil liberties and privacy groups, as well as some members of McConnell’s own party, said he was trying to weaken the bill and warned he could scuttle its ultimate passage. Several House members said that if his amendments passed they wouldn’t sign on, and the provisions of the Patriot Act that had expired at 12:01 a.m. Monday would stay off the books indefinitely. That would have created an almost unimaginable political scenario: McConnell becoming the man who kept the Patriot Act provisions dead, something Paul had tried and failed to do.

In the leadup to a full Senate vote on McConnell’s amendments, there was much hand-wringing and uncertainty. Senator John Cornyn of Texas, the majority whip, said he was ready to call the House lawmakers’ bluff, telling senators not to fall for “some fantasy” that the House would rather let the Patriot Act remain lapsed rather than sign on to McConnell’s amendments.

But as the body broke for lunch and meetings, Cornyn and McConnell seemed to sense they were losing control of their caucus. In a press conference moments before the votes on amendments, Cornyn invoked the specter of terror in the form of the recent shootings at a cartoon contest in Garland, Texas, where artists would be given a prize for the best caricature of Mohammed. Two gunmen died in an apparently assault on the event, a moment that Cornyn said “struck close to home for me.”

The senator warned that the FBI has home-grown terrorism investigations open in every one of its 56 field offices, and that if surveillance authorities to monitor them weren’t reinstated, the nation would be at grave risk.

A majority of senators apparently agreed, but they refused to follow Cornyn and McConnell’s lead. Every one of McConnell’s amendments was voted down, thanks in large part to last-minute whipping by Republican Senator Mike Lee, one of the most prominent backers of the Freedom Act, who persuaded half a dozen GOP members to abandon the leader and vote for the bill.

As the Senate moved forward with a final on the Freedom Act, a furious McConnell took to the floor and ridiculed the bill as an endorsement of Obama’s “efforts to dismantle our counterterrorism tools.”

“The Senate will vote on whether or not we should take one more tool away from those who defend this country every day,” McConnell said, adding that he could not support a bill that “surely undermines American security by taking one more tool from our warfighters at exactly the wrong time.”

Lee dismissed McConnell’s protestations in a press conference following the vote.

“It’s no secret that Senator McConnell and I disagree on this issue,” he said. “He has his opinion. It’s not something I share. At the end of the day, his preferred approach was not able to garner enough votes to move forward—not anywhere near enough votes to move forward.”

Lee even thanked McConnell’s Senate foes and Obama, counting himself among those hailing the Freedom Act as a milestone. “We appreciate the support we got from Democrats and Republicans, and the White House,” he said. “This is a monumental victory, and one victory of which I’m especially proud. I’m very pleased to have had the opportunity to work with Senator Leahy.”

While privacy activists celebrated on social media after the Senate vote, they’ve also known that the Freedom Act, while historically significant, was a relatively modest curtailing of surveillance powers.

“These reforms are important first steps, but that does not mean Congress can wash its hands of these issues and move on,” Elizabeth Goitein, the co-director of the Liberty and National Security Program at the Brennan Center for Justice, said in a statement. “Congress must vigilantly monitor the executive branch’s implementation of this law to ensure that the law’s intent is respected. Congress also must address the question of what happens to all the information about innocent Americans that will continue to be collected ‘incidentally’ under these and other authorities.”

Goitein was referring to other surveillance programs that aren’t affected by the new law and that, while aimed at foreigners, sweep up large amounts of communications of innocent Americans. In particular, surveillance conducted under Section 702 of the Foreign Intelligence Surveillance Act is responsible for the majority of information that the NSA collects on global communications networks, current and former officials say. That authority is set to expire in 2017, setting the stage for another surveillance debate that could be far more contentious than the one that just passed, because the NSA will fight tooth and nail to keep those authorities.

“Now that the Congress has passed a prohibition against bulk collection, it should be expanded to other authorities, including Section 702,” Amie Stepanovich, U.S. policy manager at Access, a privacy rights group, said in a statement.

And while Senator Dianne Feinstein, the top-ranking Democrat on the Senate Intelligence Committee, supported the USA Freedom Act, she said there was time enough in the future to strengthen surveillance authorities.

“I think we get the House in play [now]… and we can make changes later on,” Feinstein told The Daily Beast before the vote. And after the vote, Feinstein said in a statement, “I believe we can make further changes to the program.”

Get ready for round two.

—Alexa Corse and Tim Mak contributed reporting.