Washington: President Barack Obama on Tuesday signed into law landmark legislation ending the government’s bulk telephone data dragnet, significantly reversing American policy by reining in the most controversial surveillance programme since 9/11.

The bill was given final passage earlier Tuesday by the US Senate, after being approved by the House several days earlier.

The measure reauthorises key national security programmes that had lapsed early this week.

“Glad the Senate finally passed the USA Freedom Act. It protects civil liberties and our national security,” President Barack Obama said on Twitter shortly before he signed it.

In a separate statement earlier, Obama chided lawmakers for the “needless delay and inexcusable lapse in important national security authorities,” in the days leading up to the bill’s eventual passage.

“My administration will work expeditiously to ensure our national security professionals again have the full set of vital tools they need to continue protecting the country,” the president said.

The bill halts the National Security Agency’s ability to scoop up and store metadata — telephone numbers, dates and times of calls — from millions of Americans who have no connection to terrorism.

It shifts responsibility for storing the data to telephone companies, allowing authorities to access the information only with a warrant from a secret counterterror court that identifies a specific person or group of people suspected of terror ties.

“It’s a historic moment,” Senator Patrick Leahy, the senior Democratic sponsor of the bill, said after the 67-32 vote, describing the bill as “the first major overhaul of government surveillance laws in decades.”

The vote follows days of sharp debate on the floor, with many Republicans split over their support for strong counterterror measures and the need for personal privacy protections in the wake of former NSA contractor Edward Snowden’s bombshell revelations about the bulk data dragnet in 2013.

The fugitive Snowden, alternatively seen as a villain by intelligence backers and a hero by supporters of stronger civil liberties, hailed the congressional action as “historic”.

Speaking by live video link from Russia at an Amnesty International event in London shortly before the bill was passed, Snowden called efforts to end mass surveillance “not enough” but “an important step”.

The Republican divisions, as well as delay tactics by Senator Rand Paul, a 2016 presidential candidate, forced an expiration of the bulk data collection programme and two other sections of the USA Patriot Act, roving wiretap and lone-wolf tracking authorities, all of which expired at midnight Sunday.

The legislation that passed on Tuesday would reauthorise the latter two provisions.

The strong vote marked a stunning rebuke to Senate Majority Leader Mitch McConnell, who sought in vain to amend the bill.

One of the changes would have extended the transition period from six months to a year from NSA storage to telecoms storage of the data.

Another would have stripped out a provision that declassifies rulings by the secret Foreign Intelligence Surveillance (FISA) Court, a move critics have argued would erode important transparency that was built into the Freedom Act.

The changes were rejected, with at least 11 Republicans opposing McConnell to vote against the amendments.

McConnell decried the reform bill as “a step backward”.

“This is going to diminish our ability to respond to the myriad threats we have today,” he said in a provocative floor speech in which he accused the Obama administration of withdrawing from leadership in the battle against extremism.

“It is also a resounding victory for those who continually plot against our homeland,” McConnell said.

The vote occurred against a backdrop of Republican infighting and tension about the bill.

House leaders had warned that any change to the bill could delay its final passage or even kill it, which would have meant several national security authorisations expiring for good.

Many major internet firms declared victory with the congressional approval.

“The USA Freedom Act realises hard-fought and much-needed wins for internet users everywhere, including prohibiting the bulk collection of user data,” Yahoo said in a statement.

But Republican presidential candidate Marco Rubio, a Florida senator who voted against the act, slammed it as result of “weak presidential leadership”.

“The USA Freedom Act weakens US national security by outlawing the very programmes our intelligence community and the FBI have used to protect us time and time again,” Rubio said.

“Unfortunately, weak presidential leadership combined with a politically motivated misinformation campaign have now left the American people less safe than we’ve been at any point since the 9/11 attacks,” he added.

Hawkish Republican Senator John McCain, who also voted against it, added that a diverse array of possible threats meant the “intelligence community must have access to the vital authorities and capabilities they need to stop another terrorist attack before it happens.”