By Agence France-Presse
The court ruling handed a major victory to Trump in a tortuous legal battle over the Republican leader's efforts to restrict immigration.
But it follows two embarrassing climbdowns on illegal migration, as Trump and Congress face mounting pressure to legislate a solution to the flashpoint issue.
Conservative jurists prevailed over liberals in Tuesday's majority opinion from America's highest court. The 5-4 ruling validated the third and most recent version of the ban, which applies to travelers from five mainly Muslim nations -- Iran, Libya, Somalia, Syria and Yemen -- and from North Korea, about 150 million people in total.
Trump pounced on the decision as an endorsement of his authority to defend national security and "a tremendous success and victory for the American people."
Protesters took to the streets from Washington to Los Angeles and New York to bemoan the decision, and oppose the administration's hardline approach on the southern border, where 2,000 children remain separated from their migrant parents.
Trump's executive order "does not exceed any textual limit on the president's authority," wrote Chief Justice John Roberts in the majority opinion, capping a battle that began just days after Trump took office in January 2017.
"The government has set forth a sufficient national security justification to survive rational basis review. We express no view on the soundness of the policy."
- 'Anti-Muslim animus' -
A week into his presidency, Trump fulfilled a campaign promise and announced a 90-day ban on travelers from Iran, Iraq, Libya, Somalia, Sudan, Syria and Yemen.
He repeatedly questioned the loyalty of Muslim immigrants and after a 2015 terror attack in San Bernardino, California, used his campaign to propose a "total and complete shutdown of Muslims entering the United States."
Prepared in secret, the sudden order created chaos as hundreds of travelers were blocked at airports -- with protesters warning that Trump was banning Muslims in violation of the US Constitution's religious freedom protections.
Courts in several states ruled the measure illegal, and did so again in March 2017 after the administration dropped Iraq from the list.
Trump angrily recast the ban again. Issued in September, the latest version was open-ended, dropped Sudan, and added North Korea and a selection of Venezuelan officials.
Opponents -- and the court's liberal-leaning justices -- decried what they saw as a measure targeting Muslim countries, and referred back to Trump's anti-Muslim statements during his election campaign.
The worst attacks in the United States since the Al-Qaeda hijackings on September 11, 2001 have been committed either by Americans or immigrants from countries not affected by the travel ban.
In a scathing dissenting opinion, Justice Sonia Sotomayor wrote: "Based on the evidence in the record, a reasonable observer would conclude that the Proclamation was motivated by anti-Muslim animus."
- 'Open borders agenda' -
The American Civil Liberties Union, at the forefront of the fight against the ban, led an avalanche of criticism.
"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. History has its eyes on us -- and will judge today's decision harshly," the ACLU tweeted.
Democrats in Congress sounded off too.
"This is a backward and un-American policy that fails to improve our national security," said top Senate Democrat Chuck Schumer.
Immigration has been among the thorniest issue in American politics for decades, and the Trump administration last week rolled back its hardline border policy following an international outcry.
Five days after halting family separations, on Monday it stopped automatically arresting and prosecuting parents crossing illegally from Mexico with their children.
One reason, acknowledged US Customs and Border Protection Commissioner Kevin McAleenan, was the lack of sufficient detention space.
Border control agents will continue to refer for prosecution single adults who cross over illegally, however -- while Trump suggested at the weekend that migrants who "invade" the US should be sent back home without due process.
Attorney General representing 18 US states filed suit Tuesday challenging the practice of separating migrant families as "inhumane, unconscionable, and illegal."
Three undocumented mothers also filed suit in Los Angeles demanding to be reunited with the daughters they were forcibly separated from after crossing the Mexican border to seek asylum.
US Attorney General Jeff Sessions defended Trump's hard line during a speech in Los Angeles -- where police made two dozen arrests as around 200 people protested against his visit.
"As the president often says, a country without borders is not a country," he said -- vowing to keep fighting back against Democrats who push "a radical open borders agenda."
But Republicans, who control Congress, face deep internal divisions on immigration.
The House of Representatives intends to vote Wednesday on a broad immigration bill that ends family separations, but passage is in doubt. Should the bill fail, it would be a dramatic embarrassment for Trump's party.
Hannah Hanmer, who was protesting with her baby, said she was angry the government was trying "to remove human dignity from immigrants" arriving with children.
"I want to be one of the people who said no," the 26-year-old told AFP.