The US Senate has convened a rare Sunday session in a last-ditch attempt to pass legislation to allow US spy agencies to continue to sweep up information on Americans' telephone calls and other business records.

Failure to pass such legislation would mean key provisions of the USA Patriot Act would expire and, facing a midnight (5am Irish time Monday) deadline, the National Security Agency would have to shut off a vast surveillance system.

The Patriot Act was signed into law by Republican President George W. Bush after the 9/11 attacks.

Parts of it have been renewed under Democratic President Barack Obama.

But with the clock ticking on some sections of the act, efforts to renew them have stalled in the Senate, which also has failed to advance a compromise bill known as the USA Freedom Act that would reform the telephone data programme.

Libertarians want the programme ended altogether, while security hawks want it extended, unchanged.

The Senate came back early from its Memorial Day recess to resume consideration of the legislation, just as security officials said they had to begin shutting down the NSA programme to meet the midnight deadline.

Although Republicans control both the Senate and House of Representatives, the party's leaders have been unable to agree on how to deal with the deadline.

The Freedom Act, which ends the spy agencies' bulk collection of domestic telephone ‘metadata’ and replaces it with a more targeted system, has already passed the House of Representatives by an overwhelming margin and has Mr Obama's strong support.

John Boehner, the Republican speaker of the House, issued a statement just before the Senate opened, urging it to pass the Freedom Act quickly.

"Anyone who is satisfied with letting this critical intelligence capability go dark isn't taking the terrorist threat seriously," he said.

Senator Rand Paul, a libertarian campaigning to become the Republican candidate in next year's presidential election, has vowed to force the programme to expire, calling it government intrusion on privacy rights.

It is unclear if supporters of the Freedom Act can get the 60 votes needed to move it forward in the 100-member Senate.

A previous attempt on 23 May fell three votes short and the bill's backers have been pushing hard to sway three more senators.

Under the USA Freedom Act, the telephone records would be held by telecommunications companies, not the government, and the NSA would have to get court approval to gain access to specific data.

The existence of the NSA programme was revealed by former contractor Edward Snowden in 2013, prompting calls for reform.