The U.S. Senate has voted against a bill that would rein in the National Security Agency's bulk collection of telephone records within the country, possibly killing any NSA reforms until next year.

Supporters of the USA Freedom Act, in a Senate vote late Tuesday, failed to get the 60 votes needed to end debate and move toward a final vote on the legislation. Fifty-eight senators voted to end debate, while 42 voted against it.

While supporters said the legislation is needed to restore public trust in U.S. intelligence services, opponents said the NSA's widespread collection of U.S. phone records is needed to keep the country safe from terrorism.

The legislation, sponsored by Senator Patrick Leahy, a Vermont Democrat, would have "gutted" the NSA phone records collection program at a time when the U.S. faces major threats from homegrown terrorists, said Senator Marco Rubio, a Florida Republican. If the U.S. has another terrorist attack, "the first question we will be asked is, why didn't we know about it, and why didn't we prevent it?" he said.

Supporters "cannot cite a single example of this program ever being abused," Rubio said. "We are dealing with a theoretical [privacy] threat."

Senator Mike Lee, a Utah Republican, countered that the bill is needed to restore confidence in U.S. intelligence gathering services, after the public learned about widespread surveillance programs through leaks by former NSA contractor Edward Snowden. The public is concerned that the NSA "had been collecting and storing enormous amounts of information about American citizens," he said. "The data collection at issue was not limited to those suspected of terrorist activity."

Leahy criticized opponents of the bill for using "scare tactics" to defeat the legislation. He promised to keep fighting for NSA reforms.

The bill had support from President Barack Obama's administration and a wide range of U.S. tech companies and civil rights groups.

The Senate bill would require the NSA to use specific targeting terms when collecting U.S. telephone records, and would require the government to issue reports on the number of people targeted in surveillance programs.

It would give communications providers options for how to report the number of surveillance requests they receive, and require the U.S. Foreign Intelligence Surveillance Court to appoint a panel of advocates to argue in support of individual privacy and civil liberties during consideration of surveillance requests.