Before approving the extension of the law, known as Section 702 of the FISA Amendments Act, the House voted 233 to 183 to reject an amendment that proposed a series of overhauls. Among them was a requirement that officials get warrants in most cases before hunting for and reading emails and other messages of Americans swept up under the program.
Earlier on Thursday, President Trump contradicted his own White House and top national security officials in a Twitter post that criticized an important surveillance law just as Congress began debating whether to approve it. But less than two hours later, the president appeared to reverse himself, telling lawmakers to “Get smart!”
Mr. Trump’s first tweet on the topic appeared to encourage lawmakers to support limiting the law.
He was referring to an explosive and largely uncorroborated dossier that details claims about ties between Russia and Mr. Trump and his aides.
The tweet enraged Republican leaders on Capitol Hill who have been trying to chart a course to renew it, more or less intact. Speaker Paul D. Ryan and Mr. Trump spoke by phone between the president’s two tweets, according to a senior Republican congressional aide. Asked about the president’s conflicting tweets, Mr. Ryan said Mr. Trump has always been in support of foreign surveillance.
“His administration’s position has been really clear from Day 1, which is: 702 is really important, it’s got to be renewed,” Mr. Ryan told reporters after the vote.
Representative Nancy Pelosi, the House Democratic leader, asked Mr. Ryan to pull the bill from consideration, according to a senior Democratic aide familiar with the request. But Republicans, battling a last-minute push from conservative lawmakers, gambled on moving forward with a vote.
After it was approved, the American Civil Liberties Union said the legislation will give more spying power to the Trump administration.
“No president should have this power,” Neema Singh Guliani, a policy counsel with the A.C.L.U., said in a statement. “Yet, members of Congress just voted to hand it to an administration that has labeled individuals as threats based merely on their religion, nationality or viewpoints.”
Republican leaders in both the House and the Senate had counted on enough moderate Democrats and Republicans to stick together to extend the legal basis for the surveillance program, with only minimal changes. John F. Kelly, the White House chief of staff, was spotted in a House cloakroom talking to members before the vote in a last-minute lobbying push.
Mr. Trump, who is known to watch Fox News while he is tweeting, posted his tweet shortly after a Fox News legal analyst appealed directly to the president during a Thursday morning segment about the coming House vote. The analyst, Andrew Napolitano, turned to television cameras and said, “Mr. President, this is not the way to go.” He added that Mr. Trump’s “woes” began with surveillance.
By midmorning, in a follow-up tweet, the president appeared to step back from supporting the limits that his own administration has been encouraging lawmakers to reject.