WASHINGTON — Congress moved Thursday toward renewing a critical intelligence program despite a morning of confusion prompted by President Donald Trump’s tweets, in which he appeared to support significant changes that his administration had worked for months to rebuff.

The House voted on a bipartisan basis to renew intelligence agencies’ broad authority to monitor terrorist and foreign adversary communications under the Foreign Intelligence Surveillance Act, or FISA; the measure now heads to the Senate for a vote.

The House vote came after it had rejected an amendment supported by a coalition of civil libertarians and privacy advocates that would have placed new limits on the government’s ability to use communications involving American citizens.

But the president injected some last-minute drama to the proceedings. Though the White House on Wednesday strongly urged lawmakers to defeat the reform amendment, Trump appeared to take a different position in a tweet Thursday morning. He called FISA “controversial” and claimed without offering evidence that the program may have been used to “so badly surveil [sic] and abuse” his presidential campaign.

For nearly two hours, lawmakers and members of his own administration scrambled to explain the comment. House Speaker Paul D. Ryan, R-Wis., spoke by phone with Trump, and White House Chief of Staff John Kelly was dispatched to the Hill. Amid confusion over whether Trump’s original tweet put the program in jeopardy, House Minority Leader Nancy Pelosi, D-Calif., asked Ryan to cancel the vote.

The president then issued another tweet in which he appeared to endorse reauthorizing the program despite his complaints. “With that being said, I have personally directed the fix to the unmasking process since taking office and today’s vote is about foreign surveillance of foreign bad guys on foreign land. We need it!”

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

With that being said, I have personally directed the fix to the unmasking process since taking office and today’s vote is about foreign surveillance of foreign bad guys on foreign land. We need it! Get smart! — Donald J. Trump (@realDonaldTrump) January 11, 2018

The main issue is not about listening to terrorists talking to foreigners in real time. Nearly everyone agrees that should keep happening. But under the eavesdropping authorized by the law's Section 702, the NSA incidentally collects a lot of communications of Americans without individual warrants.

Critics, including Sen. Rand Paul, R-Ky., on the right and Sen. Ron Wyden, D-Ore., on the left, want to impose a requirement that the FBI go to court and get a warrant every time it wants to search the data for the communications of an American. They argue that government should not be able to prosecute someone for tax evasion if incriminating emails happen to be swept up by the NSA or the FBI. But the FBI objects to this requirement, saying the data was lawfully collected and a warrant requirement would slow their agents down. They are not using this data to prosecute Americans for tax evasion, they say — they are using it for terrorism cases.

Paul suggested during an appearance Thursday on NBC's “Morning Joe” that he may have helped influence the president’s thinking in recent conversations.

“The way I understand the president’s position is that he wants some of the reforms, that he thinks that we ought to have a warrant to look at this and that there’s a possibility that people with bias in the intelligence community could use that bias to actually abuse the system,” he said.

But the White House, in opposing those reforms, said the amendment would “re-establish the walls between intelligence and law enforcement that our country knocked down following the attacks of 9/11.” And last month, CIA Director Mike Pompeo, a former congressman from Kansas, warned that allowing the program to lapse would return the United States “to a pre-9/11 mindset in terms of how we conduct our intelligence sharing.”

“You'll recall the deep criticisms the intelligence committee for not sharing, for creating stovepipes and walls and barriers, it's variously described. What Section 702 was designed and intended to do was to knock down those walls,” Pompeo said at an event hosted by the Foundation for Defense of Democracies.

It wasn’t clear if the president was conflating his longstanding concerns over unmasking procedures with the types of reforms advocated by an unusual bipartisan coalition. The chairman of the House Intelligence Committee, Rep. Devin Nunes, R-Calif., had pushed for new restrictions on the ability of spy agencies to reveal the identity of Americans who are not the target of investigation when they come into contact with terrorists or foreign agents.

The issue has special resonance for Trump, who has questioned why the Obama administration may have revealed the identities of Trump campaign figures who interacted with foreign officials.

Those unmasking procedure changes were included in an initial version of the FISA reauthorization in December, but were pulled as it appeared they would jeopardize the program when it was set to expire that month; Democrats had unanimously opposed the legislation when it was voted on by the committee.

This week, Trump signed a memo ordering the director of national intelligence to recommend changes that could be made internally. Though they would not have the force of law, Nunes has said he would still support renewing the program. The national intelligence director announced the specifics of those changes Thursday as the House was voting.

Top lawmakers strongly criticized the president’s last-minute intervention into the sensitive debate.

“This is irresponsible, untrue, and frankly it endangers our national security. FISA is something the President should have known about long before he turned on Fox this morning.,” Sen. Mark Warner of Virginia, the top Democrat on the Senate Intelligence Committee, said on Twitter.

Sen. Richard Blumenthal, D-Conn., echoed those sentiments, saying, "This issue is paramount in importance, difficult, and complex and all the president’s doing is confusing the American public, which is really unfortunate for our national security."