WASHINGTON — The Senate rejected legislation Wednesday that would allow the FBI to search Americans’ Internet browsing histories and email records without a warrant.

Supporters invoked the Orlando massacre to push for the measure, saying it would help federal agents identify terrorist suspects and thwart future attacks. But privacy rights advocates said the bill’s sponsors were using the mass shooting as a way to expand government surveillance and get around constitutional protections against unreasonable searches and seizures.

Senators voted 58-38 to advance the legislation, falling two votes short of the 60 votes needed. The amendment by Sens. John McCain, R-Ariz., and Richard Burr, R-N.C., would have been added to a federal spending bill that included funding for the FBI. Senate Majority Leader Mitch McConnell, R-Ky., switched his vote from “yes” to “no” — a procedural move that will allow him to bring the legislation up again later.

It was the second time in two weeks that security hawks and privacy rights advocates have clashed in the wake of the Orlando shootings, in which a lone gunman killed 49 people and wounded 53 others at a gay nightclub. The House last week defeated a measure to ban warrantless surveillance of Americans’ electronic communications.

The McCain-Burr legislation would not allow FBI agents to read the actual content of emails. Instead, agents would be able to see email subject lines and the addresses that someone sends email to or receives email from, as well as when the communication took place. The FBI also would be able to see the website addresses that someone entered on their Internet browsers and look at how much time the person spent on a particular website.

Agents would be able to access the information using national security letters — a kind of administrative subpoena that does not require a court order and would likely bar an Internet provider from telling its customers that their communication was searched. Currently, the FBI must get a warrant to obtain the data.

The legislation, which was supported by the FBI and other law enforcement groups, also would make permanent a provision of the USA Patriot Act anti-terrorism law that allows federal agents to conduct surveillance of “lone wolf” terrorist suspects in the U.S. who do not have ties to a foreign terrorist group. The provision is set to expire at the end of 2019.

“In the wake of the tragic massacre in Orlando, it is important our law enforcement have the tools they need to conduct counterterrorism investigations and track ‘lone wolves,’ or (Islamic State)-inspired terrorists who do not have direct connections to foreign terrorist organizations but who seek to harm Americans,” McCain said.

Sen. Ron Wyden, D-Ore., a strong privacy rights advocate who serves on the Senate Intelligence Committee, said the bill “won’t make our country safer, but it will take away crucial checks and balances that protect our freedom.”

“FBI agents will be able to demand the records of what websites you look at online, who you email and chat with, and your text message logs, with no judicial oversight whatsoever,” Wyden said. “The reality is the FBI already has the power to demand these electronic records with a court order under the Patriot Act. In emergencies, the FBI can even obtain the records right away and go to a judge after the fact. This isn’t about giving law-enforcement new tools, it’s about the FBI not wanting to do paperwork.”

The legislation was opposed by civil liberties groups and tech companies, including Google, Yahoo and Microsoft.

“It would dramatically expand the ability of the FBI to get sensitive electronic information without any court oversight,” the American Civil Liberties Union wrote in a letter to senators urging them to vote against the measure.

Burr acknowledged that the legislation wouldn’t have stopped the Orlando massacre. But he said it could help prevent a future attack, and he vowed to look for another opportunity to pass the measure.

“I am disappointed that the Senate is currently at a stalemate even though the majority clearly supports this important amendment,” Burr said after the vote. “The threat posed by the Islamic State and other terror groups continues to grow…We cannot sit idly by while more Americans are endangered.”

FreedomWorks, a libertarian-leaning group, urged the bill’s sponsors to “abandon this effort to grow the surveillance state and undermine Americans’ constitutionally protected freedom.”

“We agree that federal law enforcement should have the tools it needs to protect Americans,” said FreedomWorks CEO Adam Brandon. “But these tools must respect the Fourth Amendment’s safeguards against unreasonable searches and seizures. Federal law enforcement must be required to respect these protections and get a warrant before obtaining information about any American.”