The Senate failed Tuesday evening to advance legislation on bipartisan surveillance reform, dealing a significant setback to the Obama administration’s plans to end the National Security Agency’s mass collection of Americans’ communications records.

Although advocates vowed to continue to press for curbs, prospects are uncertain, some officials said privately as a GOP-controlled Congress takes over in January and as public attitudes might begin to shift because of renewed fears of terrorism.

Lawmakers fell two votes shy Tuesday of the 60 needed to proceed to a floor debate on the USA Freedom Act, a measure intended to put limits on the so-called bulk collection of Americans’ records.

The failure to advance the bill, endorsed by the Obama administration, probably pushes to next year a contentious debate over how far to rein in the government’s spy powers. The debate began with the revelation last year of the NSA collection effort by former agency contractor Edward Snowden.

Sen. Patrick J. Leahy (D-Vt.), the chairman of the Judiciary Committee and a bill co-sponsor, vowed that he “will not give up the fight.” Reminding senators that 13 years ago he was the target of an anthrax-laden letter that killed the person who opened it, he said “fomenting fear stifles debate and constructive solutions.”

Former National Security Agency contractor Edward Snowden in Moscow. (AP)

Leahy has not ruled out trying again in the lame-duck session, an aide said, such as by attaching the bill to other legislation that is moving forward.

But one senior administration official said privately, “Everybody thinks it’s done for this Congress.”

Congress and the administration face a June 1 expiration of a key provision of the USA Patriot Act that enables the intelligence community to gather data for counterterrorism purposes. Section 215 allows the government to obtain specific records relevant to particular investigations. But, as Snowden disclosed, it also was the authority cited by the government to enable the NSA to collect data in bulk. Reform advocates want to end that bulk collection but in general maintain the government’s ability to issue targeted orders for data.

The 58-to-42 vote exposed fissures in the GOP over the legislation, with national security-oriented members and a vocal privacy proponent, Sen. Rand Paul (R-Ky.), voting to block the bill — but for different reasons.

Paul, a likely 2016 presidential candidate, opposed the USA Freedom Act because he said it does not go far enough to limit surveillance powers.

The incoming majority leader, Mitch McConnell, a fellow Kentucky senator, also opposed the bill, but for the opposite reason: It went too far, he said, in constraining the U.S. intelligence community.

“This is the worst possible time to be tying our hands behind our backs. The threat from ISIL is real,” McConnell said in a floor statement earlier Tuesday, using one of several names for the Islamic State. His theme was reinforced by other senators and former intelligence officials, who alluded to a series of beheadings of Americans in the Middle East by the terrorist group as a reason not to curb spy agencies’ powers. And four GOP senators voted in favor of advancing to debate — among them Sen. Ted Cruz (Tex.), who also is a potential presidential candidate.

In January, citing the potential for abuse, Obama called on Congress to find a way to end the NSA data storage, while preserving its ability to obtain needed data. The bill would require the NSA to request specific data from phone companies under specified limits.

The agency now collects call times, dates and durations of calls but not the content of calls. The government would need to show it had reasonable, articulable suspicion that the number it is interested in is tied to a foreign terrorist organization or individual.

It would also require the federal surveillance court to appoint a panel of public advocates to advance legal positions in support of privacy and civil liberties, and would expand company reporting to the public on the scope of government requests for customers’ data.

The failure to pass legislation before next year could pose hurdles for the GOP.

“They have all these grand plans — all these things that they want to accomplish,” said another Senate aide, referring to McConnell’s desire to achieve an ambitious agenda in his first 100 days as majority leader. “If they get stuck in intraparty quagmires on this and stuck up against a sunset with the prospect of losing a major national security tool, it’s a conundrum.”

It will be a challenge as well for the administration. “There’s a worry about being boxed in next year,” said one U.S. official, who spoke on the condition of anonymity because he was not authorized to speak for the record. The concern is that the debate will get pushed to the last minute — just before the Patriot Act provisions expire.

“If you wait to the last minute,” the official said, “that does not lead to good policy.”

The House passed its own version of USA Freedom in May, but it did not win the backing of privacy advocates. A modified bill that addressed most privacy concerns emerged in the Senate this summer after lengthy negotiations among intelligence agencies, the White House, lawmakers and their aides, and privacy advocates.

The bill ended up with the support of the administration, including the director of national intelligence and attorney general, as well as many tech companies and a diverse range of groups, including the National Rifle Association and the American Civil Liberties Union.