Rep. Justin Amash suffered a legislative defeat on Wednesday in a fight to rein in the NSA that elevated the Michigan Republican’s status as an independent-minded libertarian willing to stand up to powerful interests in both parties.

The House voted 205-217 to narrowly defeat Amash’s amendment, which would have stripped funding for an NSA program that collects the telephone records of people in the United States — but not the content of calls. The measure drew the ire of House Republican leaders and the White House, sparking a behind-the-scenes effort by House Speaker John Boehner to prevent the provision from coming to the floor as part of the larger debate over the defense appropriations bill.

But the Ohio Republican was once again unable to control the conservative wing of his party — a theme that has dominated his tenure as speaker — with civil liberties advocates in the GOP threatening to oppose any attempt to quash the amendment.