The House voted Thursday to renew a controversial surveillance program, following mixed messages from President Trump shortly before the vote 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 256-164. The bill now heads to the Senate.

Trump briefly took aim Thursday morning at the surveillance program despite his administration's official support for renewing it, suggesting the program 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 up for renewal in a House vote Thursday.

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 an alternative FISA bill by the libertarian Republican Michigan Rep. Justin Amash, which would have imposed multiple restrictions on spying.

Former FBI director James Comey 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.

Republicans have long raised concerns that an anti-Trump dossier, written by a British spy and funded in part by the Democratic National Committee, was used by the FBI as justification to secure a FISA warrant and monitor members of the Trump campaign over concerns of collusion with Russian officials.

Trump had tweeted about the dossier earlier Thursday, declaring: "What a mess!"

He also answered questions Wednesday about allegations of collusion, calling the claims a "phony cloud" that has hurt the country.

"It's a Democrat hoax that was brought up as an excuse, for losing an election," he said.

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