Media playback is unsupported on your device Media caption President Obama has urged Congress to prevent surveillance legislation expiring, as Jon Sopel reports

The US Senate is meeting in a rare weekend sitting to try to avert the expiry of anti-terrorist laws that let security services collect phone data.

Senators have failed to extend key provisions of the law, known as the Patriot Act, which are set to expire at midnight local time (04:00 GMT).

Senators are still debating the USA Freedom Act, a replacement bill that would water down bulk data collection.

Barack Obama has warned that the US will be at risk if the laws expire.

If a deal is not reached by midnight, security services will lose the ability, in addition to bulk phone data collection, to monitor "lone wolf" terror suspects and to carry out "roving wiretaps" of suspects, under the provisions of the Patriot Act.

The National Security Agency (NSA), which operates the data collection programmes, has already begun switching off its servers to meet the midnight deadline. Any restart of the servers will now take the best part of a day.

The Senate failed to reach a deal to extend parts of the Patriot Act, but voted by a large margin (77-17) to debate the Freedom Act, which would extend some surveillance powers, but oblige phone companies to retain data and impose greater controls on how that data could be accessed.

However, the Republican Senator Rand Paul has said he will delay the vote for several days. This mean it could take until Wednesday for the bill to be voted on - leaving a brief gap in the security services' surveillance powers.

Senator Paul, who is seeking the Republican nomination for President, has vowed to do all in his power to block or delay the surveillance laws.

"This is what we fought the revolution over, are we going to so blithely give up our freedom?" he told the Senate. "I'm not going to take it anymore."

Media playback is unsupported on your device Media caption Rand Paul: "This is what we fought the revolution over"

Image copyright Reuters Image caption US Senate Majority Leader Mitch McConnell (centre) faces opposition from some Republican colleagues

Ever since National Security Agency contractor Edward Snowden revealed that the phone records of tens of millions of Americans were being collected en masse by the NSA, the pressure to revise the programme has been intense, BBC Washington correspondent Gary O'Donoghue says.

A court has already ruled the practice illegal and the Freedom Act has already been backed by the House of Representatives and the White House.

US Director of National Intelligence James Clapper has warned that allowing the laws to expire would mean the security services losing an important capability to track US associates of foreign terrorists.

Americans have become used to this kind of political gridlock over budget measures but less so over provision affection national security, says the BBC's Tom Bateman.

Obama warning

The Senate began its session in Washington at 16:00 local time (21:00 GMT), just hours before the deadline.

In his weekly address on Sunday, President Barack Obama again warned that failure to act by the Senate could put Americans at risk.

"We shouldn't surrender the tools that help keep us safe," he said.

Bulk data collection rulings

NSA phone surveillance first revealed in June 2013 by Edward Snowden

Federal judge in Washington rules in December 2013 that mass collection may be unconstitutional

A week later, a New York district judge says it is legal

House of Representatives passes bill in May 2014 to end NSA bulk collection

A few days later, President Barack Obama tells Congress to pass a bill ending the practice

US spy leaks: How intelligence is gathered