The US Supreme Court ruled that President Donald Trump has authority to ban travellers from certain majority-Muslim countries. Picture: Reuters/Erin Schaff/File Photo

Washington - The Supreme Court ruled Tuesday that President Donald Trump has the authority to ban travellers from certain majority-Muslim countries if he thinks that it is necessary to protect the country, a priority of the president's since his first week in office.

The vote was 5-4, with conservatives in the majority and Chief Justice John Roberts writing the opinion.

The president reacted on Twitter: "SUPREME COURT UPHOLDS TRUMP TRAVEL BAN. Wow!"

Later, the White House issued a formal response that also took a swipe at his declared enemies. It called the ruling "a vindication following months of hysterical commentary from the media and Democratic politicians who refuse to do what it takes to secure our border and our country."

Lower courts had struck down each of the three iterations of the president's travel ban, the first of which was issued just in January 2017. But the administration had been hopeful about the Supreme Court, because it had previously decided to let the ban go into effect while considering the challenges to it.

The decision was one of a string of 5-to-4 decisions this term in which the justices on the right have reasserted themselves, after the addition of Trump-nominated Justice Neil Gorsuch last year restored a conservative majority.

The campaign of Senate Majority Leader Mitch McConnell, R-Ky., who kept the Republican-controlled Senate from voting on President Barack Obama's nominee to the court after the death of Justice Antonin Scalia in 2016, celebrated by posting a picture on Twitter.

It was of him shaking hands with Gorsuch.

Roberts tried to downplay the political aspects of the case, writing that the presidential proclamation that led to the ban "is squarely within the scope of presidential authority." And he rejected arguments that it was based on the predominant religion of most of the affected countries.

"The Proclamation is expressly premised on legitimate purposes: preventing entry of nationals who cannot be adequately vetted and inducing other nations to improve their practices," he wrote. "The text says nothing about religion."

He added: "We express no view on the soundness of the policy."

Justice Sonia Sotomayor wrote a stinging rebuttal, joined by Justice Ruth Bader Ginsburg.

And she read part of it in a dramatic moment on the bench.

She highlighted the president's campaign statements calling for a "complete and total shutdown" of entry into the United States by Muslims. She noted the anti-Muslim videos the president shared on Twitter, including one titled "Muslim destroys a statue of Virgin Mary!"

"Take a brief moment and let the gravity of those statements sink in," she said.

"And then remember," Sotomayor added, that the statements and tweets were spoken or written "by the current president of the United States."

Sotomayor repeatedly called out the president by name in her lengthy statement and said the majority's decision "repeats the tragic mistakes of the past" and "tells members of minority religions" in the United States that "they are outsiders."

The court, she said, "blindly accepts the government's invitation to sanction an openly discriminatory policy" and is essentially "replacing one gravely wrong decision with another."

Justices Stephen Breyer and Elena Kagan also dissented.

The high-profile case called for the justices to balance their usual deference to the president on matters of national security with a never-before-seen barrage of campaign statements, tweets, retweets and comments from the president tying Muslims to terrorism.

It was the first time the high court had considered the merits of a policy that has consumed the administration since its start. It raised questions about the judiciary's role in national security issues usually left to the political branches.

Lower courts have found that the initial order and each new version since exceeded the president's authority granted by Congress and was motivated by Trump's prejudice against Muslims.

The current ban, issued last fall, barred various travellers from eight countries, six of them with Muslim majorities. They are Syria, Libya, Iran, Yemen, Chad, Somalia, North Korea and Venezuela. But restrictions on North Korea and Venezuela were not part of the challenge. Chad was later removed from the list.

The administration said the third edition of the ban responds to the judicial criticisms of the first two and was the result of a "worldwide review of the processes for vetting aliens seeking entry from abroad."

The resulting ban was no different from what past presidents have occasionally imposed, the administration said. Congress has granted authority that the president "may by proclamation, and for such period as he shall deem necessary, suspend the entry of all aliens or any class of aliens" after a finding that the entry "would be detrimental to the interests of the United States," the administration told the court.

But challengers, led by the state of Hawaii, pointed to another section of the law, which says a person may not be denied a visa "because of the person's race, sex, nationality, place of birth, or place of residence."

Allowing the president to ban citizens of a nation, the challengers said, amounts to giving the president a "line-item veto over the entire immigration code."

Breyer thought the case should be sent back to a lower court for an examination of whether a waiver program that is part of the process was actually providing exemptions. But even without that, he said, he would "on balance, find the evidence of antireligious bias . . . a sufficient basis to set the proclamation aside."

Neal Katyal, the Washington lawyer who argued the case for Hawaii and other challengers, expressed disappointment at the ruling Tuesday and called on Congress to step in.

"We continue to believe, as do four dissenting justices, that the travel ban is unconstitutional, unprecedented, unnecessary and un-American," he said. "We decided long ago that America doesn't exclude people based on nationality or religion alone. . . . The travel ban is atrocious policy, and makes us less safe and undermines our American ideals. Now that the Court has upheld it, it is up to Congress to do its job and reverse President Trump's unilateral and unwise travel ban."

The justices were reviewing a unanimous ruling from a three-judge panel of the U.S. Court of Appeals for the 9th Circuit in San Francisco. That panel said the third version of the travel ban suffered from the deficiencies of the first two - that Trump had again exceeded his lawful authority and that he had not made a legally sufficient finding that entry of those blocked would be "detrimental to the interests of the United States."

The US Court of Appeals for the 4th Circuit in Richmond struck down the ban on the constitutional question. The 9-to-4 decision took a deep dive into Trump's statements and tweets since he became president and concluded that the proclamation, like the first two, was motivated not by national security concerns but by antipathy toward Muslims.

The case is Trump v. Hawaii.