Image copyright Getty Images Image caption Spying agencies, such as the CIA, argued that they need the law

The US House of Representatives has approved a law allowing US spy agencies to continue intercepting Americans' private communications.

President Donald Trump prompted confusion before the vote with a tweet claiming the programme had been used to "abuse" his campaign.

The legislation passed 256-164, despite opposition from both sides. The 'no' votes included 45 Republicans.

Critics say the bill actually expands government powers to spy on Americans.

The act's passage follows a year-long debate about the proper scope of US electronic wiretapping after the 2013 leaks of surveillance secrets by former National Security Agency (NSA) contractor Edward Snowden.

On Thursday morning, the US president tweeted that the programme had been used by the Obama administration to "so badly surveil and abuse the Trump campaign".

Senior Democrats urged cancellation of the vote following Mr Trump's post.

Image copyright EPA Image caption Democrats like Nancy Pelosi called for the vote to be cancelled

After speaking on the phone with House of Representatives Speaker Paul Ryan, the president posted a follow-up tweet barely two hours later.

He said that "today's vote is about foreign surveillance of foreign bad guys on foreign land. We need it! Get smart!"

The programme allows US intelligence agencies to peruse the data of Americans if they communicate with a foreign surveillance target living overseas.

Some Republicans and Democrats had unsuccessfully proposed an amendment that would have required a warrant to scrutinise US citizens' data.

The bill still has to pass the upper chamber of Congress, where Republican Senator Rand Paul and Democratic Senator Ron Wyden are staunchly opposed.

"The House-passed bill does absolutely nothing to defend the vast majority of law-abiding Americans from warrantless searches," said Senator Wyden, of Oregon.

"And in many ways it expands the federal government's ability to spy on Americans."

Image copyright Getty Images Image caption The programme was created after the 9/11 attacks

The national security establishment has warned it would not be able to detect terror plots without the bill.

The surveillance programme was secretly created after the 11 September 2001 attacks.

It was legally authorised in 2008 by Section 702 of the Foreign Intelligence Surveillance Act.

The measure also empowers CIA and FBI investigators to search gathered data, including social media activity.

Section 702 is due to expire next week, though intelligence officials say it could continue until April.

Trump's first year