The Senate voted on Tuesday to finally pass the long-debated USA Freedom Act, formally ending one of the government's most controversial surveillance programs involving the collection of US phone records.

The bill passed by a vote of 62 to 32.

The legislation puts an end to the NSA's bulk collection of phone records by having telecoms store the records instead. The legislation would still allow the government to access the records, by obtaining a court order from the Foreign Intelligence Surveillance Act any time it wishes to view them, but would limit this access to records that are relevant to a national security investigation.

Rand Paul (R-Kentucky), the most vocal opponent of the bill, voted against it on the grounds that it did not go far enough in curbing the surveillance program.

Prior to the vote on Tuesday senators voted down three of four amendments proposed by majority leader Mitch McConnell, each of which would have weakened key provisions of a bill that had already been passed overwhelmingly by the House last month.

“This is a generational win for privacy and transparency,” said Center for Democracy and Technology President & CEO Nuala O’Connor. “We’ve successfully restricted government surveillance, protecting the privacy of Americans and strengthening transparency, while preserving our national security. The era of casually dismissing mass surveillance as unimportant to liberty is over – even in Congress.”