Updated

The House voted Thursday to renew a key foreign surveillance program after a heated floor debate, amid mixed messages from President Trump about his support.

The renewal of Section 702 of the Foreign Intelligence Surveillance Act (FISA), which lets agencies collect information on foreign targets abroad, was approved on a 256-164 vote. The bill now heads to the Senate.

Supporters say it's a critical tool for preventing terrorist attacks.

“We don't know what the terrorists are up to,” House Speaker Paul Ryan, R-Wis., said on the House floor ahead of the vote, warning of grave consequences if the program is not renewed. “We can't send that information to our authorities to prevent terrorist attacks. The consequences are really high.”

ryan_032217

“We don't know what the terrorists are up to,” House Speaker Paul Ryan, R-Wis., said. (AP)

But foes worry about Americans getting swept up in the process.

FISA SURVEILLANCE PROGRAM: WHAT IS IT AND WHY IS IT SO CONTROVERSIAL?

As the bill heads across the Capitol, Kentucky Republican Sen. Rand Paul, a libertarian-leaning Republican, has suggested he will mount a filibuster, saying, "No American should have their right to privacy taken away."

The bill passed by the House would allow the FBI to continue querying a key database, using search terms, for information on Americans. But in an important tweak, it would require investigators to get a probable cause warrant if they want to view the actual content of those communications.

Earlier, the House rejected a measure that would have imposed stiffer restrictions on the FBI.

Creating some confusion, Trump briefly took aim Thursday morning at the program despite his administration's official support for renewing it, suggesting 702 was used to "badly surveil and abuse" his campaign based on the "phony" Trump dossier.

“This is the act that may have been used, with the help of the discredited and phony Dossier, to so badly surveil and abuse the Trump Campaign by the previous administration and others?” Trump tweeted.

Trump's opposition, though, didn't last long. Later Thursday morning, he posted a follow-up tweet clarifying that he has sought changes to the law and voicing support for the surveillance program.

"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!" he tweeted.

It was an apparent attempt to get back on the same page with his own administration, which backs the so-called 702 program.

The White House on Wednesday had issued a statement opposing an amendment seeking to blunt some of the program's powers and shield communications of Americans who may get caught up in efforts to pick up foreign electronic communications.

The confusing tweets from the president injected last-minute drama into the votes, provoking some Democrats to call for the vote to be pulled.

“In light of the significant concerns that have been raised by members of our caucus, and in light of the irresponsible and inherently contradictory messages coming out of the White House today, I would recommend that we withdraw consideration of the bill today, to give us more time to address the privacy questions that have been raised, as well as to get a clear statement from the administration about their position on the bill,” said California Rep. Adam Schiff, the top Democrat on the House Intelligence Committee.

Earlier Thursday, the House voted down the alternative FISA plan from libertarian Republican Michigan Rep. Justin Amash, which would have imposed multiple restrictions on spying.

Former FBI director James Comey also weighed in on the bill Thursday, reflecting the views of many in the intelligence community that the program should be renewed.

“Thoughtful leaders on both sides of the aisle know FISA section 702 is a vital and carefully overseen tool to protect this country. This isn’t about politics. Congress must reauthorize it,” he tweeted.

Fox News' Chad Pergram and The Associated Press contributed to this report.