House libertarians and liberals banded together for a surprise win in their fight against the secretive National Security Agency, securing support for new curbs on government spying a year after leaker Edward Snowden's disclosures about the bulk collection of millions of Americans' phone records.

The Republican-led House voted 293-123 late Thursday to add the limits to a $570 billion defense spending bill. The provision, which faces an uncertain fate in the Senate, would bar warrantless collection of personal online information and prohibit access for the NSA and CIA into commercial tech products.

Proponents of the measure described them as government "backdoors" that give intelligence agencies an opening to Americans' private data.

"The American people are sick of being spied on," said Rep. Thomas Massie, R-Ky., who joined with libertarian Republicans and liberal Democrats to push the measure.

Rep. Tulsi Gabbard, D-Hawaii, railed against "this dragnet spying on millions of Americans."

The House was expected to pass the defense bill Friday. It still must be reconciled with a still-to-be written Senate version.

In the showdown between privacy and security, the House earlier this year overwhelmingly passed the USA Freedom Act that would codify a proposal made in January by President Barack Obama, who said he wanted to end the NSA's practice of collecting and storing the "to and from" records of nearly every American landline telephone call under a program that searched the data for connections to terrorist plots abroad.

Massie, Gabbard and other lawmakers complained that the legislation didn't go far enough, necessitating their amendment to the defense bill. The chairman of the House Judiciary Committee, Rep. Bob Goodlatte, R-Va., and other Republican and Democratic leaders pushed back, arguing that the amendment undercut their reform package that was a year in the making.

During hours of debate and votes Thursday, the House also endorsed several new roadblocks to Obama's long-sought effort to close the U.S. prison at Guantanamo Bay, Cuba.

Republicans and some Democrats repeatedly have blocked any effort to shutter the post-Sept. 11 prison to house terror suspects, and congressional furor over Obama's trade last month of five Taliban leaders for Army Sgt. Bowe Bergdahl prompted a bipartisan effort to add fresh obstacles.

The administration exchanged Bergdahl, held captive by the Taliban since 2009, for five Taliban officials who had been at Guantanamo for more than a decade. The five were sent to Qatar, where they are to remain for a year.

Lawmakers were outraged that Obama failed to notify Congress of the exchange within 30 days, as required by law. The bill would bar 85 percent of the funds in the account for overseas conflicts until Defense Secretary Chuck Hagel reassures Congress that congressional notification on Guantanamo transfers will be respected.

The House backed two other limits on the president's handling of detainees, voting 230-184 for an amendment by Rep. Tom Cotton, R-Ark., that would impose a one-year moratorium on any transfers of Guantanamo detainees. Cotton said the move was necessary so Congress could investigate "the president's lawless release of the Taliban five."

Cotton said the current Guantanamo population of 149 is "not goat-herders. These are the worst of the worst."

Rep. Peter Visclosky, D-Ind., countered that no one in the administration is even talking about transferring the worst enemy combatants, among them Khalid Sheikh Mohammed, the self-professed mastermind of the Sept. 11 attack. He complained that the measure would prevent the president from transferring detainees already cleared for movement.

The House also backed an amendment by Rep. Jackie Walorski, R-Ind., that would bar funds for transferring Guantanamo detainees to Yemen.

The legislation for the fiscal year beginning Oct. 1 would provide the funds for military operations, including actions in Iraq and Afghanistan, as well as weapons and military personnel. The White House has objected to the legislation, complaining about the Guantanamo restrictions and attempts to spare weapons from Pentagon cost-cutters.

Wary of U.S. re-engagement in Iraq three years after combat troops left, two Democrats -- Rep. John Garamendi of California and Colleen Hanabusa of Hawaii -- won voice vote approval for an amendment requiring the president to seek congressional approval for sustained military action in Iraq.

"This miscalculation is not worth repeating," Hanabusa said of Iraq during the debate. The vote came hours after Obama announced that he would dispatch up to 300 military advisers to help quell the growing Sunni insurgency in Iraq.