Image copyright AFP/Getty Image caption Mr Trump's travel ban has led to protests

A US appeals court has upheld a decision blocking President Donald Trump's revised "travel ban" on people from six mainly Muslim nations.

Ruling on a case brought by the state of Hawaii, the appeal judges found that the executive order violated existing immigration legislation.

It is a further legal setback for the president's efforts to get the ban he promised his supporters.

Mr Trump criticised the San Francisco-based court's ruling.

"Well, as predicted, the 9th Circuit did it again - Ruled against the TRAVEL BAN at such a dangerous time in the history of our country," he tweeted.

Attorney General Jeff Sessions said he disagreed with the ruling.

"President Trump's executive order is well within his lawful authority to keep the nation safe."

He added: "Recent attacks confirm that the threat to our nation is immediate and real."

The dispute may end up being decided in the US Supreme Court.

Mr Trump's own tweet from 5 June was cited in the judges' ruling.

An earlier version of the travel ban, issued by Mr Trump just days after taking office, sparked confusion at airports and protests.

In the revised executive order, the 90-day ban was to apply to people from Iran, Libya, Syria, Somalia, Sudan and Yemen. It also called for a 120-day ban on all refugees, but removed references to religious minorities.

During his election campaign, Mr Trump called for a "total and complete shutdown of Muslims entering the United States".

Reacting to the latest ruling, White House spokesman Sean Spicer defended the executive order, saying: "We need every available tool at our disposal to prevent terrorists entering the United States and committing acts of bloodshed and violence."

"We continue to be confident that the president's executive order to protect this country is fully lawful and ultimately will be upheld by the Supreme Court," Mr Spicer added.

Trump's travel ban - the story so far

Image copyright AFP

President Trump signed an executive order on 27 January, suddenly introducing a series of immigration measures, including a ban on travellers from seven Muslim-majority nations

Nationwide protests followed, before the order was halted seven days later by a federal judge in Seattle

On 9 February appeal court judges upheld the Seattle ruling

The president signed a new executive order on 6 March, including many of the provisions of the first order but no longer including Iraq, lifting the indefinite ban on all Syrian refugees, and clarifying the situation for green card holders

On 16 March federal judges in Hawaii and Maryland blocked the revised executive order in separate rulings, just hours before it was due to come into force

A federal appeals court upheld the Maryland court's ruling on 26 May

The White House filed two emergency applications with the US Supreme Court on 2 June to seek to overturn lower court rulings

On 12 June appeal court judges upheld the Hawaii ruling

The Ninth US Circuit Court of Appeals was reviewing a March ruling by a Hawaii-based federal judge that blocked parts of Mr Trump's order.

In their ruling, the judges said that "immigration, even for the president, is not a one-person show".

Image copyright AFP Image caption Mr Trump's travel bans have sparked protests and multiple court hearings

They said Mr Trump had failed to show that the entry of people from the six countries mentioned in the ban, as well as the refugees, would be detrimental to US interests.

But the judges said the government was allowed to review the vetting process for people entering the US - something the earlier Hawaii ruling had blocked.

Mr Trump has repeatedly said that the ban is necessary to protect Americans from terrorism.

Significant recent attacks in the US were not committed by citizens of any other of the six countries named in the order.

The legal ruling comes on the first anniversary of the Orlando nightclub shooting, in which a US citizen shot dead 49 people at a Florida nightclub. It was the worst mass shooting in US history.

Analysis: James Cook, North America correspondent, BBC News

This ruling is bad news for the White House but it could have been worse.

The appeal court in San Francisco did uphold the ban on the ban - but it declined to take a position on whether or not President Trump's executive order breached the US constitution.

In fact the three appeal court judges scolded the federal district court in Hawaii, whose ruling they were considering, for failing to heed the judicial principle that "courts should be extremely careful not to issue unnecessary constitutional rulings".

The lower court had concluded, among other things, that the president's executive order was driven by "religious animus" and was intended to discriminate about Muslims.

That was improper, said the federal judges in California, because the order could actually be dismissed on a statutory rather than a constitutional basis.

In particular, they argued, the order exceeded the scope of the president's "broad authority to suspend the entry of aliens or classes of aliens" because the administration had failed to prove that banning more than 180 million people from entry based on their national origin would not be detrimental to US interests.

In other words, the appeal court concluded that the president was required by law to prove his case for the ban and failed to do so.

His lawyers may now get another shot in front of the Supreme Court although it is not certain that the justices will actually decide to hear the case.

Monday's other Trump news

Trump sued over business foreign payments

Ivanka Trump condemns 'vicious' critics

Sessions to testify publicly on Russia

Trump-like Julius Caesar loses backing

Trump targeted at Spacey-hosted Tonys