The US Congress has overwhelmingly rejected President Barack Obama's veto of legislation allowing relatives of the victims of the 11 September 2001 attacks to sue Saudi Arabia.

It is the first veto override of Mr Obama's eight-year presidency.

The House of Representatives voted 348-76 against the veto, just hours after the Senate rejected it 97-1.

It means the Justice Against Sponsors of Terrorism Act will become law.

The vote was a blow to Mr Obama and to Saudi Arabia - one of the United States' longest-standing allies in the Arab world.

Mr Obama's 11 previous vetoes 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 election on 8 November.

"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.

Senator 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.

Mr Obama had argued that the bill, known as JASTA, could expose US companies, troops and officials to lawsuits, and alienate important allies at a time of global unrest.

He called Senate Minority Leader Harry Reid and wrote a personal letter to him explaining that he strongly believed enacting JASTA into law would be detrimental to US interests.

Mr Reid became the only senator to side with Mr Obama.

The Saudi government had 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 Defence Ash Carter urged politicians to sustain the veto, and in an unusual move, CIA Director John Brennan issued a statement before today's votes saying the bill 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.