Barack Obama has survived the first congressional challenge to the NSA's blanket collection of US phone records by a narrow margin.
An introduced amendment aimed at curbing the NSA's indiscriminate collection of mobile phone records and metadata was defeated by the US House of Representatives in a 205-217 vote.
The new legislation would have prevented further funding for the programme unless the NSA could prove that data collection was needed for a specific investigation, effectively ending the indiscriminate practice.
The tight outcome does however show the Obama administration (opens in new tab) that there is a high level of disquiet over the surveillance programme in Congress, especially amongst his own party ranks.
Despite calls from the president to vote down the proposals, a majority of 111-83 Democrats voted for it. In a rare cross party partnership, 94 Republicans joined them in support of the amendment.
Although put forward by Michigan's Republican representative, Justin Amash, it was the 134 Republicans who voted against his motion that produced the outcome highly favoured by Obama and the NSA chief.
Amash said he introduced the amendment to the annual Defense Department appropriations bill to "defend the fourth amendment, to defend the privacy of each and every American".
Amash also cautioned that opponents to the proposals would, "Use the same tactic every government throughout history has used to justify its violation of rights: fear.
"They'll tell you that the government must violate the rights of the American people to protect us against those who hate our freedom."
Speaking in opposition, the chairman of the House intelligence committee, Mike Rogers, also a Michigan representative, said: "Have 12 years gone by and our memories faded so badly that we forgot what happened on September 11?"
The NSA's blanket collection of phone records and online communications, authorised by secret courts, was revealed last month by whistleblower Edward Snowden who is currently seeking asylum in Russia.
Amash's defeated amendment challenged only the collection of phone metadata, and not the Prism programme, which collects users' private online communications from Internet firms including Microsoft, Facebook, Google and Yahoo.