T​he Supreme Court on Tuesday upheld President Trump’s travel ban from five Muslim-majority countries, rejecting arguments that it was prompted by discrimination against Muslims or went beyond his authority.

Trump quickly praised the ruling, the first substantial high court review on one of his administration’s policies.

“SUPREME COURT UPHOLDS TRUMP TRAVEL BAN. Wow!,” he wrote on Twitter.

The 5-4 decision backed by conservatives on the court and written by Chief Justice John Roberts found that the ban “is squarely within the scope of presidential authority.”

He dismissed claims of anti-Muslim bias.

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

But Roberts did not endorse Trump’s controversial comments or tweets during the presidential campaign about immigration and Muslims.

In a dissent, Justice Sonia Sotomayor said judging the case by the facts “a reasonable observer would conclude that the Proclamation was motivated by anti-Muslim animus.”

Justices Stephen Breyer, Ruth Bader Ginsburg and Elena Kagan joined in the dissent.

Justices Clarence Thomas, Samuel Alito, Anthony Kennedy and Neil Gorsuch sided with Roberts.

The White House in a statement called the decision “profound vindication” following months of opposition from the media and Democrats.

“Today’s Supreme Court ruling is a tremendous victory for the American People and the Constitution,” it said. “The Supreme Court has upheld the clear authority of the President to defend the national security of the United States.”

Trump established the ban in an executive order in January 2017 that limited travel into the United States from Iran, Iraq, Libya, Syria, Somalia, Sudan and Yemen.

Iraq and Sudan were later removed in different variations of the policy.

The Supreme Court in January allowed the prohibition to continue while it reviewed the case after three lower courts had ruled against it.

Hawaii, which led the challenge, said the policy was a “Muslim ban” that discriminates against people’s religion and was motivated by Trump’s comments and tweets during the campaign.

Sotomayor said the decision was on par with the court’s upholding the detaining of Japanese-Americans during World War II in Korematsu v US in 1944, which the court rejected in the travel ban decision.

Roberts said the there’s no comparison between the two.

“Korematsu has nothing to do with this case,” he wrote, adding it was “gravely wrong the day it was decided [and] has been overruled in the court of history.”

The American Civil Liberties Union said the high court erred in both Korematsu and the travel ban.

“SCOTUS has upheld Trump’s Muslim ban. This is not the first time the Court has been wrong, or has allowed official racism and xenophobia to continue rather than standing up to it,” the organization wrote on Twitter.

“In 1944, the Supreme Court allowed the US government to imprison Japanese Americans solely because of their national origin and ethnicity, based on empty claims of national security. It’s one of the most shameful chapters of US history, and today’s decision now joins it,” the posting said.

With wires