The U.S. House of Representatives has voted to continue the collection of hundreds of millions of Americans' phone records in the fight against terrorism.

The chamber rejected a measure to end the program's authority, but it was unlikely to settle the debate over privacy rights and government efforts to thwart terrorism. The vote was 217-205 on Wednesday.

The vote marked the first chance for lawmakers to take a stand on the secret surveillance program since former NSA systems analyst Edward Snowden leaked classified documents last month that spelled out the monumental scope of the government's activities.

Republican Representative Justin Amash had challenged the program as an indiscriminate collection of phone records, saying his effort was to defend the U.S. Constitution and "defend the privacy of every American."

The issue created unusual political coalitions in Washington, with the Obama administration, national security leaders in Congress and the Republican establishment facing off against libertarian-leaning conservatives and some liberal Democrats.

The measure faces strong opposition in the Senate and from the White House and is unlikely to survive in a final spending bill. Amash's measure was offered as an addition to a $598.3 billion US defense spending bill for 2014.

"Have 12 years gone by and our memories faded so badly that we forgot what happened on Sept. 11?" Representative Mike Rogers of Michigan, the Republican chairman of the Intelligence committee, said in pleading with his colleagues to back the program.

With a flurry of letters, statements and tweets, both sides lobbied furiously in the hours prior to the vote in the Republican-controlled House. The director of national intelligence, James Clapper, warned against dismantling a critical intelligence tool.

Since the Sept. 11 attacks, Congress has authorized — and a Republican and a Democratic president have signed — an extension of the powers to search records and conduct roving wiretaps in pursuit of terrorists.

Since the disclosures this year, however, lawmakers have said they were shocked by the scope of the two programs — one to collect records of hundreds of millions of calls and the other allowing the NSA to sweep up internet usage data from around the world that goes through nine major U.S.-based providers.

"We've really gone overboard on the security side," said Representative Peter Welch of Vermont, who said it was time for a full debate on behalf of U.S. taxpayers about programs long cloaked in secrecy and part of an annual classified intelligence budget of about $30 billion.

The White House and the director of the NSA, Army Gen. Keith Alexander, made last-minute appeals to lawmakers, urging them to oppose the amendment. Eight former attorneys general, CIA directors and national security experts wrote in a letter to lawmakers that the two programs are fully authorized by law and "conducted in a manner that appropriately respects the privacy and civil liberties interests of Americans."

White House press secretary Jay Carney issued an unusual statement on the eve of Wednesday's vote, arguing that the change would "hastily dismantle one of our intelligence community's counterterrorism tools."

Proponents of the NSA programs argue that the surveillance operations have been successful in thwarting at least 50 terror plots across 20 countries, including 10 to 12 directed at the United States. Among them was a 2009 plot to strike at the New York Stock Exchange.

The overall defense spending bill would provide the Pentagon with $512.5 billion for weapons, personnel, aircraft and ships plus $85.8 billion for the war in Afghanistan for the next budget year.

The total, which is $5.1 billion below current spending, has drawn a veto threat from the White House, which argues that it would force the administration to cut education, health research and other domestic programs in order to boost spending for the Pentagon.