Congress dealt President Obama a humiliating foreign-policy blow Wednesday — voting to overturn his veto of a bill that would let families of 9/11 victims sue Saudi Arabia for that country’s alleged role in the terror attacks.

The Senate voted 97-1 to override the veto, and hours later the House did the same by 348-77.

The bipartisan measure, sponsored by Democratic Sen. Chuck Schumer of New York and Senate GOP Whip John Cornyn of Texas, would create an exception in the Foreign Sovereign Immunities Act to allow victims of terrorism on US soil to sue foreign sponsors.

“This rare moment of bipartisanship is a testament to the strength of the 9/11 families and the validity of their pursuit of justice,” Schumer said in a statement. “Overriding a presidential veto is something we don’t take lightly, but it was important in this case that the families of the victims of 9/11 be allowed to pursue justice, even if that pursuit causes some diplomatic discomforts.”

New York’s entire congressional delegation voted against the president.

The rebuke angered Obama, who called it a “dangerous precedent.”

“If we eliminate this notion of sovereign immunity, then our men and women in uniform around the world could potentially start seeing ourselves subject to reciprocal laws,” he said.

“And the concern that I have had has nothing to do with Saudi Arabia per se or my sympathy for 9/11 families. It has to do with me not wanting a situation in which we’re suddenly exposed to liabilities for all the work that we’re doing all around the world — and suddenly finding ourselves subject to the private lawsuits in courts where we don’t even know exactly whether they’re on the up-and-up in some cases.

“So it’s a dangerous precedent.”

Only Senate Minority Leader Harry Reid (D-Nev.) voted to sustain it. Sen. Tim Kaine of Virginia, the Democratic nominee for vice president, did not vote.

Families of some 9/11 victims want to sue Saudi Arabian officials if it’s determined they were connected to or supported the al Qaeda hijackers, and lawmakers wrote the bill at their request.

The Senate and House unanimously passed the measure in May and September, respectively.

Saudi Arabia and its allies also warned there would be consequences for the US should the law pass.

Obama had previously issued 11 vetoes during his presidency, according to Senate records.

Watch: Press secretary Josh Earnest explains why Obama would veto the bill

