In a confusing series of tweets, Donald Trump on Thursday pushed the House to renew a critical national security program that allows spy agencies to collect intelligence on foreign targets abroad, after having earlier attacked the legislation.

A White House official said staffers had consulted with Trump after his initial tweet opposing the administration’s stance.

The House passed a bill this morning to reauthorize the key foreign intelligence collection program with an important tweak. It requires the FBI to get a warrant if it wants to view the contents of Americans’ communications swept up in the process.

The House passed what is known as Section 702 of a program that allows spy agencies to collect information on foreign targets abroad. The bill passed 256-164. The Senate must still pass the bill before it is sent to the White House for the president’s signature.

Earlier, the House rejected a measure to impose stiffer restrictions on the FBI. It would have required the FBI to get a warrant to continue even querying the database when Americans are involved.

“This vote is about foreign surveillance of foreign bad guys on foreign land,” Trump said in a morning tweet a few hours before the votes. “We need it! Get smart!”

But before that he had sent out a contradictory tweet suggesting that the programme was used to collect information that might have been used to taint his campaign.

“‘House votes on controversial FISA ACT today,’” Trump wrote, citing a Fox News headline. “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?”

Representative Adam Schiff of California, the ranking Democrat on the House intelligence committee, said Trump’s tweets were “inaccurate, conflicting and confusing”.

He suggested that a vote on the bill should be delayed until the White House’s position can be ascertained. But Republicans said the vote should be held.

The program allows US spy agencies to collect information on foreign targets outside the United States. Americans’ communications are inadvertently swept up in the process and privacy advocates and some lawmakers want to require the FBI to get a warrant if it wants to query and view the content of Americans’ communications that are in the database to build domestic crime cases.

Trump’s initial tweet linking the Fisa programme that his White House supports to the dossier that alleges his campaign had ties to Russia seemed to be in opposition to his administration’s position, potentially putting the reauthorisation vote in doubt.

His tweets came shortly after a Fox & Friends segment that highlighted the Fisa programme, calling it “controversial”. Senator Rand Paul of Kentucky, A Republican who has also made the television rounds in recent days, has pushed for less invasive spying measures.

The White House press secretary, Sarah Sanders, struggled to explain the apparent about-face as she was repeatedly questioned during Thursday’s press briefing.

Jim Acosta, CNN’s chief White House correspondent, said: “There seems to be a pattern – and correct me if I’m wrong and there is no pattern – where the president watches something on Fox & Friends and then he tweets about it.”

Pundit Andrew Napolitano had appeared on the show and criticised the Fisa programme, noted Acosta, who asked if there was a cause and effect at work. Sanders tried to deflect the question by saying: “I’m sure you are disappointed he’s not watching CNN.”

Acosta, often a thorn in the side of the administration, shot back: “I think he watches a lot of CNN, if you don’t mind me saying it.”

Sanders replied tartly: “I don’t think that’s true. Your numbers would be higher.”

There were some disapproving howls in the press room. The spokeswoman continued: “The president has a great deal of understanding. This is top of mind. He was talking about it last week. He has issued a presidential memo on it, so it’s not just something that happened this morning. It’s been an ongoing discussion and something of great importance to the president.”

In another testy exchange, Hallie Jackson, chief White House correspondent of NBC News, challenged Sanders: “His tweet today was confusing. It was contradictory. It just was.” She asked how anyone could trust that those who claim to represent the president’s position actually are.

The press secretary replied dismissively: “I think that the premise of your question is completely ridiculous and shows the lack of knowledge that you have on this process. I’ve tried several times – I’ll do it for a 10th time here. Look, the president supports the 702 but he has some very strong concerns about the Fisa programme more generally … [The tweet] wasn’t confusing for me; I’m sorry if it was for you.”

The president’s reversal was yet another example of him seemingly taking cues from television, particularly the morning Fox News show, while also personalising an issue, in this case the dossier, over a policy position.

There are no obvious links between the dossier and the reauthorization of the spying program, but Trump has repeatedly denounced the document in recent days. The dossier has been back in the news with the release of a transcript of a congressional interview with Glenn Simpson, one of the men behind it.

The document – compiled by former British spy Christopher Steele – makes an allegation that there was a “conspiracy of cooperation” between Russian agents and the Trump campaign, and the president has frequently scorned it since its publication last January.

In March last year, Trump drew fierce criticism when he suggested without evidence that Barack Obama had “wire-tapped” his offices in New York before the presidential election.