(Reuters) — The U.S. House of Representatives on Thursday passed a bill to renew the National Security Agency’s warrantless internet surveillance program, overcoming objections from privacy advocates and confusion prompted by morning tweets from President Donald Trump that initially questioned the spying tool.

The legislation, which passed 256-164 and split party lines, is the culmination of a years-long debate in Congress on the proper scope of U.S. intelligence collection – one fueled by the 2013 disclosures of classified surveillance secrets by former NSA contractor Edward Snowden.

Senior Democrats in the House had urged cancellation of the vote after Trump appeared to cast doubt on the merits of the program, but Republicans forged ahead.

Trump initially wrote on Twitter that the surveillance program, first created in secret after the Sept. 11, 2001, attacks and later legally authorized by Section 702 of the Foreign Intelligence Surveillance Act (FISA), had been used against him but later said it was needed.

Some conservative, libertarian-leaning Republicans and liberal Democrats attempted to persuade colleagues to include more privacy protections. They failed on Thursday to pass an amendment to include a requirement for a warrant before the NSA or other intelligence agencies could scrutinize communications belonging to an American whose data is incidentally collected.

Thursday’s vote was a major blow to privacy and civil liberties advocates, who just two years ago celebrated passage of a law effectively ending the NSA’s bulk collection of U.S. phone call records, another top-secret program exposed by Snowden.

The bill as passed by the House would extend the NSA’s spying program for six years with minimal changes. Some privacy groups said it would actually expand the NSA’s surveillance powers.

Most lawmakers expect it to become law, although it still would require Senate approval and Trump’s signature. Republican Senator Rand Paul and Democratic Senator Ron Wyden immediately vowed to filibuster the measure, but it was unclear whether they could persuade enough colleagues to force changes.

The Senate will hold a procedural vote on the bill next week after it returns from a break, U.S. Senate Majority Leader Mitch McConnell said on Thursday.

“The intelligence community and the Justice Department depend on these vital authorities to protect the homeland and keep Americans safe,” McConnell, a Republican, said in a statement.

The White House, U.S. intelligence agencies and Republican leaders in Congress have said they consider the surveillance program indispensable and in need of little or no revision.

Before the vote, a tweet from Trump had contradicted the official White House position and renewed unsubstantiated allegations that the previous Democratic administration of Barack Obama improperly surveilled the Republican’s 2016 presidential campaign.

“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?” the president wrote in a tweet.

“We need it!”

The White House did not immediately respond to a request to clarify Trump’s tweet, but he posted a follow-up less than two hours later, after speaking on the phone with House Republican leader Paul Ryan.

“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!” Trump tweeted.

Unmasking refers to the largely separate issue of how Americans’ names kept secret in intelligence reports can be revealed.

After the vote Thursday, Ryan, asked about his conversation with the president, said Trump’s concerns regarded other parts of the law.

“It’s well known that he has concerns about the domestic FISA law. That’s not what we’re doing today. Today was 702, which is a different part of that law. … He knows that and he, I think, put out something that clarifies that,” Ryan told reporters.

Asked by Reuters at a conference in New York about Trump’s tweets, Rob Joyce, the top White House cyber official, said there was no confusion within the Oval Office about the value of the surveillance program and that there have been no cases of it being used improperly for political purposes.

Trump’s tweets on surveillance marked the second time this week that he appeared to veer from the administration’s position. During a meeting on Tuesday to discuss immigration with a bipartisan group of legislators he initially voiced support when Democratic Senator Dianne Feinstein suggested a “clean” bill to protect undocumented immigrants brought to the United States as children.

House Majority Leader Kevin McCarthy pointed out that a “clean” bill would not include the security and border wall that Trump has insisted be part of any immigration plan.

Press secretary Sarah Sanders told reporters there was no contradiction in Trump’s tweets on the surveillance program and that he was voicing broader concerns about FISA.

Without congressional action, legal support for Section 702 will expire next week, although intelligence officials say it could continue through April.

Section 702 allows the NSA to eavesdrop on vast amounts of digital communications from foreigners living outside the United States through U.S. companies such as Facebook, Verizon Communications, and Alphabet’s Google.