WASHINGTON — President Barack Obama nixed a bill Friday that would have allowed the families of 9/11 victims to sue the government of Saudi Arabia, arguing it undermined national security and setting up the possibility that Congress might override his veto for the first time of his presidency.

The bill had sailed through both chambers of Congress, with final passage just days before the 15th anniversary of the 9/11 attacks that killed nearly 3,000 people. But the White House said the bill, which doesn’t refer specifically to Saudi Arabia, could backfire by opening up the U.S. government and its officials to lawsuits by anyone accusing the U.S. of supporting terrorism, rightly or wrongly.

“I have deep sympathy for the families of the victims of the terrorist attacks of Sept. 11, 2001,” Obama wrote to the Senate in a veto message about the bill, known as the Justice Against Sponsors of Terrorism Act. But, he said, “the JASTA would be detrimental to U.S. national interests more broadly, which is why I am returning it without my approval.”

The move paves the way for Congress to try to override the veto, which requires a two-thirds vote in the House and Senate. Never before has Congress managed to overturn one of Obama’s vetoes, but proponents have said they’re confident they have the backing needed.

With lawmakers eager to return home to campaign ahead of the November election, a vote could come as early as Tuesday. Senate Majority Leader Mitch McConnell’s office said the Senate would take up the override “as soon as practicable in this work period.”

Sen. Chuck Schumer of New York, the Senate’s No. 3 Democrat and a traditional Obama ally, came out swinging against Obama’s veto while predicting lawmakers would reverse it “swiftly and soundly.”

“The families of the victims of 9/11 deserve their day in court, and justice for those families shouldn’t be thrown overboard because of diplomatic concerns,” Schumer said.

A coalition of 9/11 victims’ families, meanwhile, said they were “outraged and dismayed.” In a response circulated by their lawyers, the families insisted the bill would deter terrorism, “no matter how much the Saudi lobbying and propaganda machine may argue otherwise.”

Fifteen of the 19 men who carried out the attacks were Saudi nationals. Families of the victims spent years lobbying lawmakers for the right to sue the kingdom in U.S. court for any role elements of Saudi Arabia’s government may have had in the attacks. Saudi Arabia, a key U.S. ally in the Middle East, strongly objected to the bill.

Obama long had objected, too, warning that if U.S. citizens are allowed to take the Saudis into court, then foreign countries could do the same to the United States, its diplomats and its service members. The administration was also apprehensive about undermining a longstanding yet difficult relationship with Saudi Arabia. The U.S. relies on the Saudis as a counter to Iran’s influence in the region as well as to help combat the spread of terrorism throughout the Middle East.

Since the bill’s passage, the White House has lobbied aggressively to persuade lawmakers to withdraw support, and found some sympathetic listeners. The bill had passed by voice vote — meaning lawmakers didn’t have to go on the record with their positions — and the White House was hoping the prospect of a recorded vote would lead some Democrats to reconsider publicly rebuking their president.

Still, the White House said it was unclear whether it had peeled off enough lawmakers to block a veto override.

Debate about the bill has spilled onto the presidential campaign trail, as candidates vie to appear tough on terrorism. The issue is one of a few where Democrat Hillary Clinton has publicly disagreed with Obama, with her campaign saying Friday that she supports efforts to “hold accountable those responsible” for the attacks.

In the run-up to Obama’s veto, the White House said the system the U.S. uses to identify and punish countries that support terrorism was set by law and is more effective than a “patchwork” of legal decisions.

The bill’s proponents disputed arguments of a boomerang effect if the measure were to become law. Another sponsor, Rep. Peter King, R-N.Y., said foreign governments cannot look the other way if terrorist activities are being plotted or launched from inside their borders.

The bill had triggered a threat from Saudi Arabia to pull billions of dollars from the U.S. economy if it was enacted. But Saudi Foreign Minister Adel bin Ahmed Al-Jubeir denied in May that the kingdom made any threats over the bill. He said his country had warned that investor confidence in the U.S. would shrink if the bill became law.

The House vote on Sept. 9 came two months after Congress released 28 declassified pages from a congressional report into 9/11. The pages reignited speculation over links that at least a few of the attackers had to Saudis, including government officials. The allegations were never substantiated by later U.S. investigations into the terrorist attacks.

Brian McGlinchey, director of advocacy for the website 28pages.org, said making the documents public “strengthened the resolve of 9/11 families and other advocates of justice to bring about the enactment” of the bill.

He said a decision by Obama to deny the 9/11 families “their well-deserved day in court would truly stain his legacy.”