Lawmakers have given the Obama administration a bipartisan warning: patience is growing thin with its expansive and unwarranted surveillance of Americans.

In one of the most unusual votes in years, the House on Wednesday barely defeated an amendment to curtail the National Security Agency’s collection of every phone record, limiting it to records of people targeted in investigations. The vote was 205 to 217, and what was particularly remarkable was that 94 Republicans supported the limits, along with 111 Democrats who stood up to intense lobbying by the White House and its spy agencies.

The amendment was sponsored by Representative Justin Amash, a Republican of Michigan, one of the most anti-government libertarians in the House. On this issue, he found common ground with Democrats and moderate Republicans who are also concerned that the N.S.A. is needlessly violating the privacy of ordinary citizens.

Representative F. James Sensenbrenner Jr., a Republican of Wisconsin and an author of the Patriot Act, said the measure imposes the standard for collecting data in a criminal trial. Representative Jerrold Nadler, a Democrat of New York, said the amendment would reimpose the original intent of Congress.