WASHINGTON — A spy program that sweeps up vast amounts of electronic communications survived a legislative challenge in the House of Representatives Wednesday, the first move to curb the surveillance effort since a worker leaked details of its scope.

The House of Representatives voted 217-205 to defeat an amendment to the defense appropriations bill that would have limited the National Security Agency's ability to collect electronic information, including phone call records.

The measure, which has been opposed by the White House and intelligence chiefs, was the first attempt to curb NSA spying since former NSA contractor Edward Snowden leaked details about the extent of the agency's data collecting.

New Hampshire's Ann Kuster, a Democrat, was among those in Congress voting against the amendment.

"Rep. Kuster strongly believes we can and must protect both our national security and our constitutionally protected right to privacy, and she is committed to conducting vigorous oversight of our country's intelligence operations. She supports a bipartisan measure that would ban the NSA from acquiring the content of Americans' phone calls and emails without undermining counterterrorism tools that help keep our country safe," Kuster spokesman Rob Friedlander said in a statement Wednesday night.

Congresswoman Carol Shea-Porter, also a Democrat, voted yes on the amendment.

"As we have all seen in the last few months, government intelligence activities are in dire need of more transparency," she said in a statement. "I voted for this amendment because it would have helped keep our government accountable to the people and still allows for the collection of necessary information."