Senate Intelligence Committee Chairman Richard Burr (R-N.C.), right, sitting next to the panel’s ranking Democrat, Sen. Mark R. Warner (Va.), speaks on Capitol Hill on March 30. (Susan Walsh/AP)

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 its 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, allows the National Security Agency to collect from U.S. companies 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.

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. 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.

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.

Democrats and Republicans are freshly at each other’s throats over a new memo that the GOP says is a vital to exposing “abuse” of the surveillance authority in other parts of FISA, but Democrats maintain it is a politically motivated sucker-punch to cripple the law enforcement agencies looking into allegations of Trump’s Russia ties.

The House Intelligence Committee voted along party lines Thursday to make the short memo of available to all House members to read in a secure facility. Some Republicans who have viewed the document are calling on the committee to release the memo publicly — something panel members are, so far, resisting.

Rep. K. Michael Conaway (R-Tex.), a senior member of the intelligence panel, said the memo’s contents reference an “important” list of “problems we have discovered with FISA, writ large,” that they thought all members should be aware of. He said the memo would be the inspiration for forthcoming legislative proposals — but that those would be handled by the Judiciary Committee.

But Democrats are accusing Republicans of using the memo as a thinly veiled way of “attacking the FBI and its handling of the investigation” into Trump’s suspected Russia ties, that is “rife with factual inaccuracies,” according to the top Democrat on the intelligence panel, Rep. Adam Schiff (Calif.).

“This may help carry White House water, but it is a deep disservice to our law enforcement professionals,” Schiff said.

Republicans and Democrats have long bickered over whether the Obama administration improperly surveilled Trump affiliates, and various members of the GOP have questioned whether the past administration relied on a controversial dossier as a basis for that surveillance.