Image copyright Reuters Image caption Senator Rand Paul spoke on the Senate floor to prevent the bill's passage

The US Senate has voted to limit the government's ability to collect phone data, a policy that had been in place since the attacks of 11 September 2001.

The USA Freedom Act extends the government's ability to collect large amounts of data, but with restrictions.

The bill, which replaces the Patriot Act, had been backed by President Barack Obama as a necessary tool to fight terrorism.

Mr Obama later signed the bill into law.

The new law undoes a national security policy that had been in place since shortly after the attacks on 11 September 2001.

It replaces a National Security Agency (NSA) programme in which the spy agency collected personal data en masse.

The revelation of this programme by former NSA contractor Edward Snowden triggered a global public backlash.

Instead of receiving bulk quantities of data from telephone and internet companies the NSA will now be forced to request the information through a court order.

The data will also be stored on telephone and internet company servers rather than government servers.

The request must be specific to an individual entity such as a person, account, or electronic device.

A six-month transition will be in place as the policy shifts so that data storage remains with private companies, rather than on government servers.

Patriot Act vs Freedom Act

What is changing? The expiry of the Patriot Act brings to an end bulk collection of Americans' phone metadata - who called who, when and for how long, but not the content of calls - by the US. Under its successor, records must be held by telecommunications companies and investigators need a court order to access specific information. Technology companies will be given greater leeway to reveal data requests. The measures are intended to balance concerns on privacy with providing the authorities the tools they need to prevent attacks.

What stays the same? Key parts of the Patriot Act are retained in the Freedom Act. They include the provision allowing the monitoring of "lone wolf" suspects - potential attackers not linked to foreign terror groups, despite the US authorities admitting the powers have never been used. The Freedom Act also maintains a provision allowing investigators to monitor travel and business records of individuals, something law officers says is more effective than bulk collection.

The law's passage had been temporarily blocked by libertarian-minded senators who are fearful of government's intrusion into individuals' private lives.

Kentucky senator and presidential hopeful Senator Rand Paul repeatedly criticised the bill from the Senate floor.

"We are not collecting the information of spies. We are not collecting the information of terrorists. We are collecting all American citizens' records all of the time," Mr Paul said. "This is what we fought the revolution over."

President Obama had earlier criticised Congress for the "needless delay and inexcusable lapse in important national security authorities".

The Freedom Act had been approved by the House of Representatives and the White House but the Senate rejected it last week by a vote of 57-42.

Once it became clear that the Patriot Act extension would not be possible, senators voted to move forward with the Freedom Act.

Republican Senate Leader Mitch McConnell, also from Kentucky, fought to prevent any rollback in surveillance powers.

Speaking on the floor of the Senate Mr McConnell said the law will "take one more tool away from those who defend our country every day".