Chief Justice John Roberts gave the landmark opinion and the court's other four conservative judges also ruled in favour of the president.

The four liberal justices dissented.

What about the two previous versions of the ban?

The original order issued in January 2017 barred people from seven majority-Muslim countries - Iran, Iraq, Syria, Yemen, Somalia, Sudan and Libya - from entering the US for 90 days.

It also halted refugee resettlement for 120 days and banned Syrian refugees indefinitely.

Chaos ensued at airports, where there was some confusion about enforcement.

That travel ban was later blocked by federal courts.

The revised order in March removed Iraq from the list, after it agreed to boost co-operation with the US, and it also lifted the indefinite ban on Syrian refugees.

It was also struck down but in June 2017, the Supreme Court allowed that version of the policy to take partial effect, against travellers without close links to the US.

A third version of the ban was issued in September, taking Sudan off the list but adding Chad, North Korea and Venezuelan government officials.

Why were those countries chosen?

The latest travel ban says that the countries "remain deficient at this time with respect to their identity-management and information-sharing capabilities, protocols, and practices. In some cases, these countries also have a significant terrorist presence within their territory".

Critics have noted that major attacks such as the 9/11 New York attacks, the Boston marathon bombing and the Orlando nightclub attack were carried out by people from countries not on the list, such as Saudi Arabia, Egypt and Kyrgyzstan, or by US-born attackers.

Is it a 'Muslim ban'?

This was a crucial question in the legal battle, as six out of eight countries on the list are predominantly Muslim.

Media playback is unsupported on your device

Media captionMuslim students on Trump ban: 'I don't belong here'

In one early challenge, a US district judge in Virginia ruled the first order was unconstitutional because it had religious bias at its heart - an appeals court in the same state ruled along the same lines on the second ban too.

Ruling on the second version, the Hawaii court also dismissed the government's argument that the ban is not anti-Muslim because it targets all individuals from the six countries, regardless of religion, and the countries themselves represent only a small fraction of the world's Muslim population.

"The illogic of the government's contentions is palpable. The notion that one can demonstrate animus toward any group of people only by targeting all of them at once is fundamentally flawed," the court ruling said, pointing out that the countries' populations were between 90% and 99% Muslim.

The court also cited statements made by Mr Trump, such as a 2015 press release calling for "a total and complete shutdown of Muslims entering the United States".

But the Department of Justice has said a distinction should be made between things said as a candidate and as president.