Saudi Arabia has warned of "disastrous consequences" from a United States law allowing relatives of the victims of the September 11 attacks to sue the kingdom.

On Wednesday, the US Senate voted overwhelmingly on to override President Barack Obama's veto of the Justice Against Sponsors of Terrorism Act (JASTA).

JASTA allows relatives of terrorism victims to pursue cases against foreign governments in US federal court and to demand compensation if such governments are proven to bear some responsibility for attacks on US soil.

The Saudi Foreign Ministry condemned its passage in a statement on Thursday.

"The erosion of sovereign immunity will have a negative impact on all nations, including the United States," it said.

A Saudi foreign ministry source called on the US Senate "to take the necessary measures to counter the disastrous and dangerous consequences" of the law.

The unnamed spokesman, cited by the official Saudi Press Agency, said the law was "a source of great worry".

Riyadh is one of Washington's longest-standing and most important allies in the Middle East and part of a US-led coalition fighting Islamic State militants in Iraq and Syria.

In opposing the law, Mr Obama said it would harm US interests by undermining the principle of sovereign immunity, opening up the US to private lawsuits over its military missions abroad.

Republican leaders of the Senate and House of Representatives have expressed doubts about the legislation and blamed Mr Obama for not consulting them adequately.

House Speaker Paul Ryan said the Senate might have to "fix" the legislation to protect US troops in particular.

Families of 9/11 victims have campaigned for the law — convinced that the Saudi Government had a hand in the attacks that killed almost 3,000 people.

Riyadh denies having any role in the attacks.

AFP/Reuters