WASHINGTON -- President Donald Trump's puzzling tweets about a key U.S. spying law threw the House into temporary disarray Thursday, but lawmakers ended up renewing the law - with a new restriction on when the FBI can dig into the communications of Americans swept up in foreign surveillance.
During a hectic morning of House votes and presidential tweets, Trump's national intelligence director also issued new guidance for how officials can find out the names of Americans whose identities are blacked out in classified intelligence reports.
Trump has said previous rules were far too lax and led to damaging leaks about top aides, a claim fiercely contested by Democrats.
The new guidelines on "unmasking" Americans, however, were a side show to the House showdown over the Foreign Intelligence Surveillance Act, reauthorizing a collection program set to expire on Jan. 19. The bill passed 256-164 and is now headed to the Senate. It would extend for six years the program, which includes massive monitoring of international communications.
Trump has said he'll sign the renewal, but his first tweets Thursday suggested he had suddenly turned against the program, alarming intelligence officials.
In one tweet, Trump linked the program to a dossier that alleges his presidential campaign had ties to Russia.
"'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?"
Trump then spoke by telephone with House Speaker Paul Ryan, according to a Republican familiar with the call but not allowed to publicly discuss private conversations.
And a short time later, Trump changed his tune. "This vote is about foreign surveillance of foreign bad guys on foreign land," he tweeted. "We need it! Get smart!"
Democrats pounced on his earlier criticism.
"This is irresponsible, untrue, and frankly it endangers our national security," Sen. Mark Warner of Virginia, the Senate intelligence committee's top Democrat, tweeted. "FISA is something the President should have known about long before he turned on Fox this morning."
National Intelligence Director Dan Coats applauded the House action, saying it was a critical step in protecting Americans and U.S. allies and "I have faith that my former colleagues in the Senate will follow the House's lead."
"Our security is not a partisan issue," said Coats, a former senator from Indiana.
Lawmakers had begun the day readying for two votes related to the program that intelligence officials call the "holy grail" because it provides insight into the thinking and actions of U.S. adversaries.
While the program focuses on foreign targets, Americans' emails, phone calls and other communications get vacuumed up in the process. Privacy advocates and lawmakers from both parties have argued for years that government agencies should have to get warrants if they want to look at Americans' communications in the database.
The bill approved by the House allows the FBI to continue scanning the database, using search terms, for information on Americans. But it would require investigators to get probable cause warrants to view the actual content in cases unrelated to national security.
Exceptions would apply, such as for murder, kidnapping and other crimes specified in the bill. The House rejected an alternative proposal that would have imposed stiffer restrictions on the FBI, requiring warrants to query the database at all.
Rep. Adam Schiff, the House intelligence committee's top Democrat, warned that stiffer restrictions would "cripple" the intelligence program. He described the bill that passed as reaching a "very sensible balance."
However, fellow California Democrat Zoe Lofgren, who backed the defeated proposal, warned the government was gathering "the content of your phone calls, content of your emails, content of your text messages, video messages," and searching them "for crimes that have nothing to do with terrorism."
The vote cut across party lines, with 65 Democrats joining 191 Republicans to pass the bill. Forty-five Republicans and 119 Democrats voted no.
There are no obvious links between the dossier Trump spoke of, which includes salacious but unsubstantiated allegations against him, and the reauthorization of the spying program, or between the program and Trump's oft-repeated claims that the Obama administration wiretapped Trump Tower during the presidential campaign.
Top intelligence and FBI officials and Republicans in Congress have rejected the wiretapping accusations as false.
CNN reported last year that details from the dossier were used in part to get a warrant to monitor Trump adviser Carter Page after the FBI independently corroborated them. The Associated Press hasn't independently confirmed the report.
White House aides scrambled on Thursday to explain Trump's apparent about-face, saying the president was happy to see the House approve the bill.
"We weren't confused, but some of you were," press secretary Sarah Sanders said.
Just as the House was voting, National Intelligence Director Coats issued his own guidance on how redacted names of Americans in intelligence reports can be requested and disclosed. Only top intelligence officials or their designees can approve such requests, which must be justified and documented.
Coats' policy is designed to prevent names from being disclosed for political reasons, especially during presidential transitions. But Republicans and Democrats dispute whether there is any need for the change.
Republicans have alleged that Obama administration officials improperly shared the identities of Trump presidential transition team members mentioned in intelligence reports. Democrats say there is no evidence that happened.