President Trump listens before signing a law to curtail opioids trafficking in the Oval Office at the White House on Jan. 10, 2018. (Jabin Botsford/The Washington Post)

At 6:46 Thursday morning, Andrew Napolitano — a Fox News Channel personality and supporter of President Trump — opined about a critical government surveillance program on “Fox & Friends,” the show that is part alarm clock, part unofficial briefing for the commander in chief.

“I’m scratching my head,” Napolitano said, referring to Thursday’s House vote to reauthorize a key part of the Foreign Intelligence Surveillance Act. “I don’t understand why Donald Trump is in favor of this.”

And then, just 47 minutes later, Trump was no longer in favor of the bill that his own White House had been championing. In a tweet, the president quoted verbatim the Fox headline from Napolitano’s appearance and suggested that the FISA law had been used by the Obama administration to “so badly surveil and abuse the Trump Campaign.”

The presidential decree — a mere 40 words — set off a mad scramble across Washington.

House Speaker Paul D. Ryan (R-Wis.) spent 30 minutes on the phone with the president explaining the differences between domestic and foreign surveillance, as many fellow Republicans reacted in disbelief and befuddlement. White House Chief of Staff John F. Kelly also directly intervened with Trump, reiterating the program’s importance before traveling to the Capitol, where he parried questions from confused lawmakers.

The House passed the Foreign Intelligence Surveillance Act bill Jan. 11, to renew a key NSA surveillance program. Here's what you need to know in 60 seconds. (Elyse Samuels,Deirdra O'Regan/The Washington Post)

A presidential correction came 101 minutes after the initial tweet. The second missive — an explanation perhaps as much for Trump himself as for anybody else — stated that “today’s vote is about foreign surveillance of foreign bad guys on foreign land.”

“We need it!” Trump concluded in his second Twitter message. “Get smart!”

The confusion — less than two hours in all — sent members of Congress reeling, the president’s staff scrambling and was a fresh reminder of how Trump’s haphazard impulses can undermine his own administration and upend the daily workings of the federal government. 

“The president’s ping-pong on attitudes toward the FISA renewal suggests to me that he doesn’t fully understand the issue, which is complicated even for experts to understand,” said John E. McLaughlin, a former head of the CIA. “For the intelligence community, it is yet another signal that the president is not fully attuned to how they operate and how carefully they stay within the law.”

Trump’s misunderstanding of the nuances of surveillance laws came as he and his aides have been struggling to silence the national debate over the president’s mental fitness in the wake of allegations in a new book about the chaotic White House.

In Thursday morning’s meeting of House Republicans, lawmakers reacted with palpable consternation to Trump’s initial tweet, according to attendees. The anxiety continued until House Majority Leader Kevin McCarthy (R-Calif.) stood up and handed his cellphone to Rep. Devin Nunes (R-Calif.), who read aloud the president’s second tweet voicing support for the bill. 

White House press secretary Sarah Huckabee Sanders answers questions during a press briefing at the White House on Jan. 11, 2018. (Matt McClain/The Washington Post)

After Kelly and other White House officials arrived at the Capitol, where they rounded up support, the House ultimately voted overwhelmingly to renew the program that allows U.S. spy agencies to gather intelligence on foreign targets located outside the United States.

The program is known as Section 702, named after the part of the 2008 FISA law that established it. But with his morning tweet, Trump seemed to be conflating Section 702 with the broader FISA law, which governs a variety of surveillance and intelligence activities. Trump charged that the FISA law had been used to get a warrant to spy on his campaign.

“ ‘House votes on controversial FISA ACT today,’ ” Trump wrote on Twitter, quoting the Fox 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?”

Napolitano’s Fox commentary was not the only opposition that Trump was exposed to. Though his own White House supported Section 702 — putting out a statement Wednesday night in support of its renewal — Trump spoke Thursday morning with two key Republican lawmakers who both opposed the bill, officials said.

Sen. Rand Paul (R-Ky.) expressed his opposition to the president, a Republican aide familiar with the conversation said. Paul has threatened to filibuster the bill when it reaches the Senate because of privacy concerns that information on U.S. citizens could be captured in the surveillance of foreign targets.

Rep. Mark Meadows (R-N.C.), the leader of the conservative House Freedom Caucus, also conveyed to the president his opposition on civil-liberties grounds, according to a person familiar with that conversation.

But at the White House on Thursday afternoon, press secretary Sarah Huckabee Sanders insisted there was no discrepancy between Trump’s two tweets — and said the only confusion was on the part of the media.

“We don’t think there was a conflict at all,” Sanders said. “The president fully supports the 702 and was happy to see that it passed the House today. . . . We don’t see any contradiction or confusion in that.” 

In a particularly contentious exchange, Sanders snapped at Hallie Jackson of NBC News for asking about the president’s contradictions: “I think that the premise of your question is completely ridiculous and shows the lack of knowledge that you have on this process.”

Sanders explained that the FISA issue was “top of mind” for Trump after a presidential memorandum was issued last week initiating a review of “unmasking” policies by the Office of the Director of National Intelligence. She said the president has “some concerns” with the FISA law generally, though not with Section 702.

“The president doesn’t feel that we should have to choose between protecting American citizens and protecting their civil liberties,” Sanders said. “He wants to do both.”

Still, scores of lawmakers were confused by Trump’s initial tweet.

One Republican senator simply rolled his eyes when asked what, exactly, the president meant. And Sen. Mark R. Warner of Virginia, the top Democrat on the Senate Intelligence Committee, offered a sharp rebuke on Twitter: “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.”

Trump’s initial criticism of the surveillance program also “freaked out” House Republican leaders, one person with direct knowledge of the fallout said. 

The president’s team quickly called Ryan. When the speaker called Trump back, the two men spoke at length about the program, with Ryan helping to articulate the nuances of the program being voted on Thursday, a person familiar with the conversation said.

“That’s called cleanup on aisle six,” quipped one Republican strategist in frequent touch with the White House, speaking anonymously to offer a more candid assessment. 

White House legislative affairs aides were already on the Hill talking to members about voting “yes” and assuring them that there would be enough support to pass the bill. The White House had not mounted a serious effort to whip votes, however, because administration officials assumed the legislation would pass easily.

At one point, Kelly and White House legislative affairs director Marc Short were spotted walking from the direction of Ryan’s office into the House chamber, where they spoke with lawmakers in a cloakroom. They had been on Capitol Hill for pre-scheduled meetings about immigration policy but found themselves fielding questions about the FISA bill.

Asked by CNN whether Trump makes legislating more difficult with behavior like his Thursday morning tweets, Kelly replied, “It’s not more difficult. It’s a juggling act.”

After the bill passed, some in the White House expressed amusement and relief that yet another crisis had been averted.

“Who saw that coming except for no one?” one White House official said, speaking anonymously to criticize the president. “You just shake your head and laugh a little bit.”

Erica Werner, Sean Sullivan and Mike DeBonis contributed to this report.