WASHINGTON — In an election-year challenge to President Barack Obama, the Republican-led House on Friday overwhelmingly approved a $570 billion defense bill that halts any Guantanamo transfers for a year in the furor over the American-for-Taliban swap and pulls back government spying.
The vote was 340-73 for the legislation that provides money for military operations in Iraq and Afghanistan, personnel, ships and aircraft. An unusual coalition of libertarian Republicans and liberal Democrats pushed through new limits on National Security Agency surveillance as the year-old revelations of bulk collection of millions of Americans’ phone records still roil the debate of security vs. privacy.
Pushing through the bill over three days, Republicans railed against Obama’s decision last month to swap five Taliban leaders who had been held at Guantanamo for more than a decade for Sgt. Bowe Bergdahl, a captive for five years in Afghanistan. The Taliban were transferred to Qatar, where they must remain for a year.
Republicans said Obama broke the law, failing to notify Congress within 30 days, and increased the terrorism risk to the United States with the exchange.
Obama has defended the deal to spare Bergdahl as the administration has tried to reduce the population of Guantanamo, where 149 are being held.
The House added a provision to the bill that would bar funds for transfers, imposing a one-year moratorium on moving Guantanamo detainees to a foreign country. It also voted to bar funds for transferring Guantanamo detainees to Yemen.
‘‘Our brave men and women in uniform have fought too hard and have sacrificed too much to have the president release these detainees who will likely return straight to the battlefield,’’ said Rep. Ted Yoho, R-Fla.
The bill already bars 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.
Earlier this year, the House overwhelmingly passed the USA Freedom Act that would codify a proposal made in January by Obama, who said he wanted to end the National Security Agency’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.
Several Republicans and Democrats said the legislation fell short in curbing NSA surveillance. They joined forces and scored a decisive win late Thursday on new limits on the agency over the objections of leaders of the Judiciary and Intelligence committees.
The bill would prohibit the agency from searching for the communications of specific American accounts within the vast trove of Internet data it has collected while targeting foreigners. Critics say that tactic amounts to improper ‘‘backdoor’’ searches because it is conducted without warrants.
Government officials argue that since the information was acquired legally, there should be no reason they can’t use it for intelligence purposes or even in criminal investigations.
The NSA obtains the Internet data both through court orders on tech companies such as Google and Facebook and also by secretly tapping fiber optic cables abroad. Though the collection targets foreigners, U.S. officials acknowledge it sweeps in significant numbers of Americans’ communications.
The bill also would bar the NSA from mandating or requesting that tech companies build secret flaws — so-called trap doors — in hardware, software or devices that would facilitate government surveillance.
‘‘The American people are sick of being spied on,’’ said Rep. Thomas Massie, R-Ky.
Despite the clamor to cut the deficit and Pentagon pleas for cost-saving reductions, lawmakers voted to spare military bases, the A-10 Warthog close air support plane and an aircraft carrier.
That drew a warning from Democratic Whip Rep. Steny Hoyer, who backed the bill but warned of a price to pay very soon.
‘‘We have to stop pretending that national security ... can somehow be magically created without having a fiscally sustainable policy,’’ said the Maryland lawmaker.
The White House has objected to the legislation, which must be reconciled with a still-to-be written version from the Democratic-led Senate.
The bill would provide $490 billion for core defense spending and $79 billion for overseas operations in Iraq, Afghanistan and other conflicts. The $79 billion is a placeholder as Congress awaits a more detailed proposal from the administration.
Wary of U.S. re-engagement in Iraq three years after combat troops left, two Democrats — Reps. 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.