A deeply divided House of Representatives has defeated legislation that would have blocked the National Security Agency from collecting vast numbers of phone records.
It handed the Obama administration a hard-fought victory in the first congressional showdown over the NSA's surveillance activities since Edward Snowden's security breaches last month.
The 205-217 vote was far closer than expected and came after a brief but impassioned debate about citizens' right to privacy and the steps the government must take to protect national security.
It was a rare instance in which a classified intelligence programme was openly discussed on the House floor, and disagreements over the programme led to some unusual coalitions.
Conservative Republicans wary of what they see as Obama administration abuses of power teamed with liberal Democrats long opposed to intrusive intelligence programmes. The administration made common cause with the House Republican leadership to try to block it.
House members pressing to rein in the NSA vowed afterwards that the outrage unleashed by Snowden's disclosures would eventually put a brake on the agency's activities.
Democrat Jerrold Nadler, said lawmakers would keep coming back with legislation to curtail the dragnets for "metadata", whether through phone records or internet surveillance.
At the very least, the section of the Patriot Act in question would be allowed to expire in 2015, he said. "It's going to end - now or later. The only question is when and on what terms."