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.