By KEN DILANIAN
AP Intelligence Writer

WASHINGTON (AP) _ The National Security Agency has begun winding down its collection and storage of American phone records after the Senate failed to agree on a path forward to change or extend the once-secret program ahead of its expiration at the end of the month.

Barring an 11th hour compromise when the Senate returns to session May 31, a much-debated provision of the Patriot Act _ and some other lesser known surveillance tools _ will sunset at midnight that day. The change also would have a major impact on the FBI, which uses the Patriot Act and the other provisions to gather records in investigations of suspected spies and terrorists.

In a chaotic scene during the wee hours of Saturday, Senate Republicans blocked a bill known as the USA Freedom Act, which would have ended the NSA’s bulk collection but preserved its ability to search the records held by the phone companies on a case-by-case basis. The bill was backed by President Barack Obama, House Republicans and the nation’s top law enforcement and intelligence officials.

It fell just three votes short of the 60 needed for passage. All the “no” votes but one were cast by Republicans, some of whom said they thought the USA Freedom Act didn’t go far enough to help the NSA maintain its capabilities.

If Senate Republican leaders were counting on extending current law and continuing the negotiations, they miscalculated. Democrats and libertarian-minded Republicans refused to go along. A bill to grant a two-month extension of the law failed, and senators objected to each attempt by Majority Leader Mitch McConnell of Kentucky offer up a short term extension.

The failure to act means the NSA will immediately begin curtailing its searches of domestic phone records for connections to international terrorists. The Justice Department said in a statement that it will take time to taper off the collection process from the phone companies. That process began Friday, said an administration official who would not be identified because he was not authorized to discuss the matter publicly.

While the phone records program has never been credited with thwarting a terrorist plot, the Senate failure also imperils other tools that the FBI has been using to hunt for suspected spies and terrorists.

The FBI uses Section 215 of the Patriot Act to gather financial and other types of records in national security cases. Another expiring provision makes it easier for the bureau to track “lone wolf” terrorism suspects who have no connection to a foreign power, and another allows the government to eavesdrop on suspects who continuously discard their cellphones in an effort to avoid surveillance.

Sen. Rand Paul, Kentucky’s other senator and a Republican presidential candidate, called the Senate’s failure to allow an extension of the surveillance programs a victory for privacy rights.

“We should never give up our rights for a false sense of security,” Paul said in a statement.

Some civil liberties groups joined Paul in praising the result, saying they would rather see the Patriot Act provision authorizing NSA phone collection expire altogether.

“For the first time, a majority of senators took a stand against simply rubber-stamping provisions of the Patriot Act that have been used to spy on Americans,” said Michael Macleod-Ball, acting director of the ACLU Washington Legislative Office.

But Nuala O’Connor, CEO of the Center for Democracy and Technology, called the Senate’s inaction “inexcusable after two years of debate and bipartisan compromise.”

And a presumed GOP presidential candidate, New Jersey Gov. Chris Christie, took a veiled swipe at Paul by blaming the failure to extend the Patriot Act on “misguided ideologues who have no real world experience in fighting terrorism.”

Section 215 of the Patriot Act is used by the government to justify collecting the “to and from” information about nearly every American landline telephone call.

When former NSA contractor Edward Snowden revealed the program in 2013, many Americans were outraged that NSA had their calling records. Obama ultimately announced a plan similar to the USA Freedom Act and asked Congress to pass it. He said the plan would preserve the NSA’s ability to hunt for domestic connections to international plots without having an intelligence agency hold millions of Americans’ private records.

Since it gave the government extraordinary powers, Section 215 of the Patriot Act was designed to expire at midnight on May 31 unless Congress renews it. An appeals court has ruled that the phone collection does not comply with the law, but stayed the ruling while Congress debated.

Under the USA Freedom Act, the government would transition over six months to a system under which it queries the phone companies with known terrorists’ numbers to get back a list of numbers that had been in touch with a terrorist number.