WASHINGTON - The Senate passed a bill on Thursday to reauthorize a powerful government authority to conduct foreign surveillance on U.S. soil, sending the president a six-year extension of the program just one day before a statutory deadline.

The 65-to-34 vote on the legislation, which the president is expected to sign into law, marks the end of a months-long debate that exposed sharp divisions between privacy advocates and national security hawks in Congress. Lawmakers have struggled over whether to limit the spy authority the intelligence community has identified as one of its most important surveillance tools.

The program, known as Section 702 of the Foreign Intelligence Surveillance Act — or FISA — allows the National Security Agency to collect from U.S. companies like AT&T and Google the emails and other communication of foreign targets located overseas. But federal law enforcement agents can scour the database for information about Americans who have been in touch with those foreign targets, and many lawmakers wanted to force the government to obtain a warrant before doing so.

Congress first legalized in 2008 the once-secret program created by the George W. Bush administration following the terrorist attacks of Sept. 11, 2001.

Advertise with us

The legislation that passed the Senate on Thursday, and the House last week, requires law enforcement agents to procure a court order before they view the content of database searches for information about Americans, if they want to later use what they find in criminal cases. The limited new warrant requirement for FBI agents to read any emails of an American who is already the subject of an open criminal investigation does complicate matters. But that requirement is so narrowly written that it would not apply to the overwhelming majority of such searches. There is no such restriction in cases involving counterterrorism, counterintelligence and counterespionage.

Efforts to impose more stringent limits failed in both chambers. In the House, proponents of tighter privacy controls were unable to gain enough support for an amendment that would have required the government to secure warrants for database searches. In the Senate, opponents’ efforts to stymie progress also fell short this week, when senators eked out just enough votes to move the bill over an important procedural hurdle despite a last-minute call from Senate Minority Leader Charles E. Schumer, D-N.Y., to slow down the debate and consider amendments to the measure.

Congress last extended that law without changes in 2012. But after the leaks in 2013 by Edward Snowden, a former intelligence contractor, a bipartisan coalition of civil-liberties-minded lawmakers pushed to impose far more sweeping warrant requirements on queries for Americans’ information that was swept in by government surveillance.

With Thursday’s final vote, that effort failed.

The bill will now head to Trump, who is expected to sign it, despite a brief episode last week when, in contradictory and seemingly misinformed tweets, he questioned his administration’s support for the measure. Extending Section 702 was the intelligence community’s top legislative priority last year. The statutory authorization for the program will end Friday.

The New York Times contributed.