The Senate Thursday passed a bill reauthorizing an important national counter-terrorism tool after a bipartisan fight over privacy protections in the legislation.

The measure, approved by the House last week, now heads to President Trump’s desk for a signature.

The legislation reauthorizes Section 702 of the Foreign Intelligence Surveillance Act, which allows intelligence officials to spy on communications of non-citizens outside of the United States, for six years.

The Senate passed the bill in a 65-34 vote despite intense opposition from a significant and bipartisan faction of lawmakers who say the moderate reforms included in the bill do not do enough to protect the privacy of Americans who are inadvertently caught up in the spying operation.

The bill nearly failed to advance on Monday when it went before Senate lawmakers and did not initially win the 60 votes needed to beat back a filibuster. Several lawmakers had to be convinced on the Senate floor to vote to begin debate on the measure.

Senate Minority Leader Chuck Schumer, D-N.Y., opposed the bill.

The bill includes moderate reforms authored by both the House Intelligence and Judiciary Committees last year. Proponents say the changes will bolster privacy protections by adding a new requirement for intelligence agencies to obtain search warrants to search communications and new congressional oversight of the kinds of searches made by the government. It also limits the use of the surveillance authority so fewer Americans are caught up in the searches and requires reforms to the way intelligence agencies search the contents of electric communications beyond the sender information.

Senate Majority Whip John Cornyn, R-Texas penned a column for CNN on Thursday to both tout the bill and defend it from criticism.

“Whether it's combating terrorism, detecting and countering cyber-attacks, or protecting troops overseas from foreign threats, this legislation reauthorizes one of the crown jewels of foreign intelligence,” Cornyn wrote. “And far from ignoring Americans' privacy concerns, the protections enshrined in the law embrace and defend them.”