The US Supreme Court has handed Donald Trump one of the biggest victories of his presidency, upholding his travel ban targeting several Muslim-majority countries and rejecting the argument that it represented unconstitutional religious discrimination.
The 5-4 ruling, with the court's five conservatives in the majority, ended a fierce fight in the courts over whether the policy amounted to an unlawful Muslim ban.
Trump quickly claimed "profound vindication" after lower courts had blocked his travel ban announced in September, as well as two prior versions, in legal challenges brought by the state of Hawaii and others.
The court held that the challengers had failed to show that the ban violates US immigration law or the US Constitution's First Amendment prohibition on the government favouring one religion over another.
Trump, who has called the travel ban necessary to protect the country against attacks by Islamic militants, reacted on Twitter, writing: "Wow!"
In a statement issued by the White House on Tuesday, Trump labelled the ruling "a tremendous victory for the American People and the Constitution" that upheld presidential authority on national security issues.
"In this era of worldwide terrorism and extremist movements bent on harming innocent civilians, we must properly vet those coming into our country," Trump said.
Writing for the court, Chief Justice John Roberts said that Trump's administration "has set forth a sufficient national security justification" to prevail. "We express no view on the soundness of the policy," Roberts added.
The current ban, announced in September, prohibits entry into the US of most people from Iran, Libya, Somalia, Syria and Yemen. The Supreme Court allowed it to go largely into effect in December while the legal challenge continued.
The challengers have argued the policy was motivated by Trump's enmity toward Muslims and urged courts to take into account his inflammatory comments during the 2016 presidential campaign. Trump as a candidate called for "a total and complete shutdown of Muslims entering the United States".
In a strident dissent that she read from in court, liberal Justice Sonia Sotomayor said there were "stark parallels" with the court's now discredited 1944 decision that upheld US internment of Japanese-Americans during World War Two. Sotomayor described at length various statements Trump made on the campaign trail.
As part of Tuesday's ruling, Roberts officially repudiated the 1944 internment ruling and he rejected the comparison, saying that the war-era practice was "objectively unlawful and outside the scope of presidential authority".
Roberts said it was "wholly inapt to liken that morally repugnant order to a facial neutral policy denying certain foreign nationals the privilege of admission".
Civil rights groups and Democrats denounced the ruling.
"The ruling will go down in history as one of the Supreme Court's great failures," said Omar Jadwat, a lawyer for the American Civil Liberties Union, which challenged the ban.
The court's decision "swallows wholesale government lawyers' flimsy national security excuse for the ban instead of taking seriously the president's own explanation for his actions", Jadwat added.
"Not since key decisions on slavery, segregation in schools, and Japanese American incarceration have we seen a decision that so clearly fails to protect those most vulnerable to government-led discrimination," added Farhana Khera, executive director of the group Muslim Advocates.
"Despite today's ruling, turning away those fleeing horrific violence and persecution or to discriminate against people based on nationality and religion continues to be as un-American as ever," said Senator Bob Menendez, the top Democrat on the Senate Foreign Relations Committee.