The US Senate 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, paving the way for the first veto override of his eight-year presidency.

The final vote was 97-1 against the veto, a blow to Saudi Arabia, a frequent US partner in the Middle East recently subject to harsh criticism in the US Congress.

Democratic Minority Leader Harry Reid was the only senator to side with Obama.

Democratic Senator Tim Kaine, a vice presidential nominee, and Bernie Sanders, an independent and former Democratic White House contender, did not vote.

The measure next goes to the House of Representatives, which is due to vote later on Wednesday.

If two-thirds of House members also support the "Justice Against Sponsors of Terrorism Act," known as JASTA, as expected, it would be the first veto override since Obama became president in 2009.

Obama's 11 previous vetos were all sustained. But this time almost all of his strongest supporters in Congress opposed 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, the third-ranking Democrat in the Senate, said in a statement.

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

He led the fight for the legislation, with Senator John Cornyn, the No. 2 Senate Republican. Kirsten Gillibrand, another New York Democrat, cast the 67th "no" vote, the number needed to override the veto in the Senate.

Obama had argued that JASTA could expose US companies, troops and officials to lawsuits, and alienate important allies at a time of global unrest. He called Reid and wrote a personal letter to him explaining that he strongly believed enacting JASTA into law would be detrimental to US interests.

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

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

Secretary of Defense Ash Carter urged lawmakers to sustain the veto, and in an unusual move, CIA Director John Brennan said it had "grave implications" for national security.