WASHINGTON — Congress on Wednesday overwhelmingly voted to override President Barack Obama’s veto of a bill to allow survivors and families of 9/11 victims to pursue their lawsuit in a U.S. court against Saudi Arabia for its alleged complicity in the terrorist attacks.

The veto override — the first for Obama — won 97-1 in the Senate and 348-77 (one member voted present) in the House despite second thoughts by some lawmakers and intense lobbying against the legislation by the Obama administration, some foreign relations experts and Saudi Arabia.

“I think it was a mistake,” Obama said on CNN. “It’s a dangerous precedent, and it’s an example of why sometimes you have to do what’s hard.”

For members of Congress, voting against 9/11 families to sustain the veto before an election would be hard, Obama said. “But it would have been the right thing to do.”

Family members who fought for the Justice Against Sponsors of Terrorism Act applauded and cheered after the House voted, making it possible that their trillion-dollar lawsuit will be reinstated eight years after an appellate court in New York sidelined it.

Most Democrats chose to support the 9/11 families’ quest to sue Saudi Arabia rather than back their president, though more members of the House than the Senate stood by him.

Before the vote, Rep. Peter King (R-Seaford), the House sponsor, urged a veto override. “It’s really essential that the House today stand on the side of justice,” King said.

advertisement | advertise on newsday

Earlier, Sen. Chuck Schumer (D-N.Y.), the Senate sponsor, did the same. “Democrats and Republicans don’t agree on much these days,” he said. “But we agree on JASTA. Both parties believe that the families of the 9/11 victims should be able to seek justice.”

Terry Strada, whose husband was killed in the World Trade Center attacks and who chairs the 9/11 Families & Survivors United for Justice Against Terrorism, said she and others who filed the lawsuit against Saudi Arabia are looking forward to their day in court.

“The victims of 9/11 have fought for 15 long years to make sure that those responsible for the senseless murder of thousands of innocent men, women and children, and injuries to thousands others, are held accountable,” she said. “JASTA becoming law is a tremendous victory toward that effort.”

Despite the lopsided vote, several senators expressed concerns and said they would vote for the override only reluctantly because of their sympathy for the 9/11 families, and House members engaged in a debate, with some urging that the veto be sustained.

Senate Minority Leader Harry Reid (D-Nev.) broke with Schumer as the lone Senate vote to sustain the veto. Reid’s office later distributed a letter from Obama to him explaining why he vetoed the bill on Friday after both chambers passed it without opposition earlier this month.

The White House listed its objections: It turns over national security and foreign policy to the courts; puts U.S. military, diplomats and assets at risk of retaliatory lawsuits by other countries; and threatens important and sensitive relationships with other nations.

Key members from both parties in the Senate and the House said they would continue to consider legislation to further narrow JASTA and to mitigate any blowback from other countries.

Rep. Mac Thornberry (R-Texas), chairman of the House Armed Services Committee, urged a vote to sustain the veto during the House debate.

“My concern for this legislation is more related to the unintended consequences it may have,” he said, echoing the Obama administration’s caution that the bill weakens the doctrine of sovereign immunity, which protects a country and its official representatives abroad.

Rep. Bobby Scott (D-Va.) agreed, saying that “this is not the way to go about getting justice.”

advertisement | advertise on newsday

What if Iraq citizens sued the United States for the 2003 bombings of Baghdad that killed and maimed so many people and won compensation for each one of them, he asked.

But Rep. Jerry Nadler (D-Manhattan), a bill sponsor, dismissed those concerns.

He said the bill is narrowly drawn and won’t put U.S. military and diplomats at risk. “We must not hold justice for the 9/11 families to imagined fears,” he said.