It was a delicate and belated legislative minuet, in pursuit of a goal that aligned Donald Trump, his House GOP allies, some Democratic adversaries, and the intelligence agencies he derides as Nazi-like. Perhaps predictably, Trump disrupted all those complex congressional machinations with a tweet.

“Like much of what the president says on Twitter, this one has thrown the morning into disarray,” observed a knowledgeable congressional aide ahead of the first critical surveillance vote of the Trump administration.

The move turned out not to be quite chaotic enough to stop the House from bailing out the National Security Agency’s most cherished recent surveillance law; the House on Thursday morning renewed an expiring legislative authority that undergirds many of NSA mass-surveillance activities. But the president’s ill-timed tweet, which called that law into question, once again prompted concern that Trump does not actually know the first thing about the overwhelming surveillance powers the House once again provided the government over which he presides.

Trump’s tweet “certainly threw everything into turmoil this morning,” said Adam Schiff, the House Intelligence Committee’s top Democrat. “I can only imagine that the reaction within the intelligence community and law enforcement and among his own cabinet was the same as it was here in Congress, which is hard to describe without the use of expletives.”

Collectively, the surveillance approved by the House is known—or obscured through bureaucratic euphemism—by the dry name of the authority, Section 702 of the Foreign Intelligence Surveillance Act.

Section 702 permits the warrantless collection of untold terabytes of communications and associated data, including Americans’ international conversations; communications on the servers of major tech firms like Apple, Facebook, Google and Yahoo; and communications in transit over the Internet. It’s ostensibly “targeted” at foreigners, but even the judges on the secret Foreign Intelligence Surveillance Court have frequently found that Americans’ communications, by the thousands, are inevitably—the term of art is “incidentally”—gathered up as well. All this occurs without any warrant.

“ I can only imagine that the reaction within the intelligence community and among his own cabinet was the same as it was here in Congress, which is hard to describe without the use of expletives. ” — Rep. Adam Schiff

Its renewal is the top legislative priority of the Justice Department and the intelligence agencies. They have spent “an extraordinary amount of time” convincing the Hill to renew Section 702, FBI Director Chris Wray told a New York audience on Tuesday.

Wray’s “fervent hope,” he continued, is that Congress “reauthorizes Section 702 and does not do so in a way that harms operational use of the program”—i.e., doesn’t attach greater privacy safeguards, such as a provision preventing his bureau from searching through already-collected Americans’ Section 702 data without a warrant.

As of 7:32 a.m, Wray had a legislative wind at his back. The outcome of a bitter fight in the House Rules Committee on Tuesday ended with the defeat of a narrow measure that would require the FBI to get a warrant for such searches. Brought by progressive Rep. Zoe Lofgren and Tea Party libertarian Rep. Ted Poe, the measure would close what’s known as the “backdoor search provision” of Section 702. Because it was tailored just to close that measure, some civil libertarians thought it stood the best shot of passing the House.

Instead, on Thursday, the House voted on an unrelated bill with a broad reauthorization of Section 702 attached. That reauthorization is based on a House intelligence committee bill that civil libertarians argue place “no limits on the use of Americans’ communications in investigations, or in legal proceedings other than criminal prosecution,” according to a Brennan Center analysis. Michigan Republican Justin Amash, a consistent opponent of mass surveillance, got a vote attached that would go much further than Poe-Lofgren in introducing privacy safeguards onto Section 702. But since it would go further, some civil libertarians feared it would get voted down and the intelligence committee version passes.

Then at 7:33 a.m., Donald Trump tweeted.

“‘House votes on controversial FISA Act today.’ 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?”

It was a tweet that has to be heavily filtered through the president’s selective view of reality to make any sort of sense. It appeared influenced by a Fox News segment that ran just before Trump grabbed his phone.

“FISA is something the President should have known about long before he turned on Fox this morning,” tweeted Mark Warner, the top Democrat on the Senate Intelligence Committee.

The House didn’t vote on the entire Foreign Intelligence Surveillance Act, which does not expire, but on its Section 702. Section 702 would not have been the authority used to collect the communications of Russian ambassador Sergei Kislyak—which also led to the collection of his conversations with disgraced former national security adviser Michael Flynn, and perhaps top aide Jared Kushner, that led to Flynn’s downfall and guilty plea. That would have been the Title 1 of of FISA, since Kislyak is, by the nature of his former job, an agent of a foreign power on U.S. soil—something that not even the most fervent civil libertarian considers a violation. And the Steele dossier has nothing to do with anything relevant here.

What was relevant was that the tweet put pressure on Trump’s House GOP allies, who had previously thought the White House was finally cool with an expansive reauthorization of Section 702. It had put out a statement last night “strongly oppos[ing]” the Amash’s USA RIGHTS amendment and backing the House intelligence bill that it said would “preserve the useful role FISA’s Section 702 authority plays in protecting American lives.”

Even getting House Republicans on the typically pro-NSA intelligence committee to endorse Section 702, as they typically do, has been an uphill struggle. Thanks to Trump’s war with the intelligence agencies, chairman Devin Nunes and other House GOP leaders have castigated a surveillance provision they never before criticized—and ultimately ended up endorsing. Nunes started suggesting in March that he would let Section 702 expire, and even after embracing it, added an unnecessary provision to help both him and Trump save face in their baseless claims that Trump aides had been surveilled illegally and then had their identities maliciously leaked.

Nunes’ gambit was one reason Section 702 is now in overtime. Only a last-minute legislative juryrigging let it survive 2017. But with eight days to go before Section 702 vanished, on January 19, Trump tweeted again at 9:14 and contradicted his earlier statement – evidently after someone had explained to him the legislative damage he had risked doing to his own agenda. For good measure, however, Trump still managed to misstate the enormous, warrantless reach into Americans’ lives that Section 702 permits: “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!”

With the floor debate and subsequent votes about to get underway, Section 702’s advocates panicked. Adam Schiff, the House intelligence committee’s ranking Democrat and a consistent ally of the NSA’s, proposed pulling the vote and regrouping. The knowledgeable congressional aide said shortly before the debate that what was about to unfold was anyone’s guess.

“It’s hard to say what the leadership will do about this. The White House was in the exact opposite position twelve hours ago,” the aide said.

“ It is clear there is a growing bipartisan coalition to protect innocent Americans from warrantless spying, and that knows it is possible to stand up for Americans’ rights. ” — Sen. Ron Wyden

Instead, the result looked rather like most surveillance votes. First Amash’s amendment went down to defeat, 183-233. Then the House intelligence committee’s version passed, 256-164. The Deep State Trump alternatively slandered and embraced had won again, with bipartisan support and bipartisan opposition.

With eight days to go before Section 702 expires, now moves to the Senate.

Sen. Ron Wyden, the Oregon Democrat on the intelligence committee and a USA RIGHTS architect, blamed a “concerted campaign of fear-mongering and misinformation” for its House defeat. But he saw a silver lining.

“With 183 House votes, it is clear there is a growing bipartisan coalition to protect innocent Americans from warrantless spying, and that knows it is possible to stand up for Americans’ rights while also keeping our people safe from foreign threats. The Senate must allow real debate and amendments, and not push this legislation through in the dark,” Wyden said.

—with additional reporting by Andrew Desiderio.