WASHINGTON - Congress voted overwhelmingly Wednesday to allow families of Sept. 11 victims to sue Saudi Arabia for its alleged backing of the attackers, handing Barack Obama the first veto override of his presidency.

Both the House and Senate voted decisively to reverse Obama's decision to scuttle the legislation. Democrats in both chambers abandoned the president in large numbers despite warnings from Obama and top national security officials that flaws in the bill could put U.S. interests, troops, and intelligence personnel at risk.

The Senate vote was 97-1. The House vote a few hours later was 348-77.

Lawmakers said their priority was the 9/11 victims and their families, not Saudi Arabia.

"The White House and the executive branch (are) far more interested in diplomatic considerations," said Sen. Chuck Schumer, D-N.Y., a sponsor of the bill. "We're more interested in the families and in justice."

Speaking at a forum in Washington, CIA Director John Brennan said he was concerned about how Saudi Arabia, a key U.S. ally in the Middle East, would interpret the bill. He said the Saudis provide significant amounts of information to the U.S. to help foil extremist plots.

"It would an absolute shame if this legislation, in any way, influenced the Saudi willingness to continue to be among our best counterterrorism partners," Brennan said.

Brennan, who said he visited lawmakers Wednesday to argue against an override of Obama's veto, noted that there is a tremendous amount of Saudi investment in the United States. "Do they want to leave them here so they could potentially be attached by some type of court ruling that is going to award the litigants?" he asked.

After senators acted, White House spokesman Josh Earnest called the vote the "single most embarrassing thing" the Senate has done in decades and "an abdication" of its responsibility. He accused members of the Senate Judiciary Committee of not understanding the legislation and its impact on the military.

Five weeks before state and national elections, lawmakers refused to oppose a measure strongly supported by 9/11 families who say they are still seeking justice 15 years after attackers killed nearly 3,000 people. Saudi Arabia, an important U.S. ally in the Middle East, is staunchly opposed to the measure.

Despite reversing Obama's decision, a group of senators acknowledged that defects in the bill could open a legal Pandora's box, triggering lawsuits from people in other countries seeking redress for injuries or deaths caused by military actions in which the U.S. may have had a role.

In a letter sent Tuesday to Senate Minority Leader Harry Reid, Obama said the bill would erode sovereign immunity principles that prevent foreign litigants "from second-guessing our counterterrorism operations and other actions that we take every day."

But proponents of the bill dismissed Obama's concerns as unpersuasive. Sen. John Cornyn of Texas, the Senate's No. 2 Republican, and other supporters said the bill is narrowly tailored and applies only to acts of terrorism that occur on U.S. soil.

"This bill is about respecting the voices and rights of American victims," Cornyn said.

Families of the victims and their attorneys dismissed concerns over the legislation as fearmongering.

Sen. Ben Cardin of Maryland, one of the Democrats who broke with Obama and voted to override, said, "The risks of shielding the perpetrators of terrorism from justice are greater than the risks this legislation may pose to America's presence around the world."

The legislation gives victims' families the right to sue in U.S. court for any role that elements of the Saudi government may have played in the 2001 attacks. Fifteen of the 19 Sept. 11 hijackers were Saudis. Courts would be permitted to waive a claim of foreign sovereign immunity when an act of terrorism occurred inside U.S. borders, according to the terms of the bill.

A group of national-security minded legislators pledged to discuss how to repair problem areas during the upcoming lame-duck session of Congress. But the fact that legislation could pass both chambers of Congress without closer scrutiny left at least a few senators chiding themselves for not examining its ramifications more closely.

The Justice Against Sponsors of Terrorism Act, or JASTA, moved to the floor of the Senate in May and was passed by voice vote. The bill cleared the House earlier this month, also by voice vote.

"We didn't pay much attention to this," said Sen. Dianne Feinstein of California, the top Democrat on the Senate intelligence committee. "And boy is that ever a lesson learned."

Obama vetoed the measure last week, telling lawmakers the bill would make the U.S. vulnerable to retaliatory litigation.

In his letter to Reid, the president said other countries could attempt to use JASTA to justify similar immunity exceptions to target U.S. policies and activities that they oppose.

In a separate letter sent Monday to a senior House member, Defense Secretary Ash Carter described the potential for foreign litigants to seek classified intelligence data and analysis and sensitive operational information to establish their cases in what could be an "intrusive discovery process."

Missing the vote were Sens. Bernie Sanders, I-Vt., and Tim Kaine, D-Va.


AP Writer Deb Riechmann contributed to this article. Follow Richard Lardner on Twitter: http://twitter.com/rplardner