WASHINGTON (Reuters) - Congress on Wednesday overwhelmingly rejected President Barack Obama’s veto of legislation allowing relatives of the victims of the Sept. 11 attacks to sue Saudi Arabia, the first veto override of his presidency, just four months before it ends.

The House of Representatives voted 348-77 against the veto, hours after the Senate rejected it 97-1, meaning the “Justice Against Sponsors of Terrorism Act” will become law.

The vote was a blow to Obama as well as to Saudi Arabia, one of the United States’ longest-standing allies in the Arab world, and some lawmakers who supported the override already plan to revisit the issue.

Obama said he thought the Congress had made a mistake, reiterating his belief that the legislation set a dangerous precedent and indicating that he thought political considerations were behind the vote.

“If you’re perceived as voting against 9/11 families right before an election, not surprisingly, that’s a hard vote for people to take. But it would have been the right thing to do,” he said on CNN.

Obama’s 11 previous vetoes were all sustained. But this time almost all his strongest Democratic supporters in Congress joined Republicans to oppose him in one of their last actions before leaving Washington to campaign for the Nov. 8 election.

“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,” Senator Charles Schumer, a top Senate Democrat, said in a statement.

Schumer represents New York, site of the World Trade Center and home to many of the nearly 3,000 people killed in the 2001 attacks, survivors and families of victims.

The law, known as JASTA, passed the House and Senate without objections earlier this year.

Slideshow ( 8 images )

Support was fueled by impatience in Congress with Saudi Arabia over its human rights record, promotion of a severe form of Islam tied to militancy and failure to do more to ease the international refugee crisis.

The law grants an exception to the legal principle of sovereign immunity in cases of terrorism on U.S. soil, clearing the way for lawsuits seeking damages from the Saudi government.

Riyadh has denied longstanding suspicions that it backed the hijackers who attacked the United States in 2001. Fifteen of the 19 hijackers were Saudi nationals.

Family members had tied their last push for the bill to the 15th anniversary of the attacks this month, demonstrating outside the White House and Capitol. On Wednesday, two fire trucks displayed a giant U.S. flag outside the Senate.

“We rejoice in this triumph and look forward to our day in court and a time when we may finally get more answers regarding who was truly behind the attacks,” Terry Strada, whose husband died in the attacks, said in a statement.

RISK TO TROOPS?

Obama argued that JASTA could expose U.S. companies, troops and officials to lawsuits if other countries passed reciprocal legislation, and may anger important allies.

He called Senate Minority Leader Harry Reid and wrote a letter to him explaining that he strongly believed enacting JASTA into law would be detrimental to U.S. interests. Reid became the only senator to side with Obama.

Slideshow ( 8 images )

Some lawmakers said the White House, which has a history of poor relations with Congress, had waited too long to fight the bill.

The Sept. 11 families have received more than $7 billion, but bill backers said their intention was to allow lawsuits to punish any government that backs terrorism on U.S. soil.

“This bill was carefully negotiated over more than six years,” Representative Jerrold Nadler, another New York Democrat, told the House.

The issue, however, may not be finished. At least 28 senators signed a letter to JASTA’s sponsors, Schumer and Republican Senator John Cornyn, asking that they work with them to mitigate any potential unintended national security and foreign policy consequences.

The Saudi government financed an extensive lobbying campaign against the legislation.

U.S. corporations including General Electric Co and Dow Chemical Co also opposed it, as did the European Union and other U.S. allies.

Secretary of Defense Ash Carter and General Joseph Dunford, chairman of the joint chiefs of staff, opposed the bill and CIA Director John Brennan said JASTA had “grave implications” for national security.

Democratic Senator Tim Kaine, Hillary Clinton’s vice presidential running mate, and Bernie Sanders, an independent and former Democratic White House contender, did not vote.

Override opponents in the House included Representative Mac Thornberry, Republican chairman of the Armed Services committee, and Adam Smith, its ranking Democrat, citing concern about U.S. forces overseas.