The court made an important exception: It said the ban "may not be enforced against foreign nationals who have a credible claim of a bona fide relationship with a person or entity in the United States."
In the unsigned opinion, the court said that a foreign national who wants to visit or live with a family member would have such a relationship, and so would students from the designated countries - Libya, Iran, Somalia, Sudan, Syria and Yemen - who were admitted to a U.S. university.
The court said it would hear the case when it reconvenes in October. But it also indicated in the ruling that things may change dramatically by then. It asked the parties to address whether the case would be moot by the time it hears it; the ban is supposed to be a temporary one while the government reviews its vetting procedures.
And the justices said they "fully expect" the government to be able to conduct its review within the 90-day span the executive order proposes.
That affects the ban on travel from the six countries and a 120-day ban on all refugees entering the United States, with the exceptions noted by the court.
In a statement, Trump called the ruling "a clear victory for our national security."
"Today's ruling allows me to use an important tool to protect our Nation's homeland. I also am particularly gratified that the Supreme Court's decision was 9-0," he said.
The president said last week the ban would go into effect 72 hours after receiving an approval from the courts.
Justices Clarence Thomas, Samuel Alito and Neil Gorsuch would have let the ban take effect as written and objected to what they called the court's "compromise."
A partial stay will "burden executive officials with the task of deciding - on peril of contempt - whether individuals from the six affected nations who wish to enter the United States have a sufficient connection to a person or entity in this country," Thomas wrote.
Such a compromise, the justices said, will lead to a "flood of litigation" over what constitutes a "bona fide relationship" before the overall case is resolved after oral argument in the fall.
They added that the court has made an "implicit conclusion" that the administration will prevail.
The proposed travel ban has been a major point of contention between Trump and civil rights groups, which say it was motivated by unconstitutional discrimination against Muslims.
Trump contends the ban is necessary to protect the nation while the administration decides whether tougher vetting procedures and other measures are needed. He has railed against federal judges who have blocked the move.
Because the executive order was stopped by lower courts, travelers from those countries have been entering the United States following normal visa procedures. Trump first moved to implement the restrictions in January in his first week in office.
His first executive order went into effect immediately and resulted in chaos at airports in the United States and abroad, as travelers from the targeted countries were either stranded or sent back to their countries.
Lawyers for challengers to the order rushed to federal courts, and the order was stayed within days. The U.S. Court of Appeals for the 9th Circuit eventually said the order could not be implemented, infuriating the president, who said he would take the case to the Supreme Court.
His lawyers told courts that the new order was written to respond to the 9th Circuit's concerns. But new lawsuits were immediately filed, and federal judges once again stopped the implementation.
A federal district judge in Maryland stopped the portion of the order affecting travelers from the six countries; a judge in Hawaii froze that portion and the part affecting the refugee programs.
Appeals courts on both coasts upheld those decisions.
The U.S. Court of Appeals for the 4th Circuit in Richmond agreed with U.S. District Judge Theodore Chuang in Maryland, who sided with opponents in finding that the ban violates the Constitution by intentionally discriminating against Muslims.
In a 10-to-3 decision, the court noted Trump's remarks before and after his election about implementing a ban on Muslims and said the executive order "in context drips with religious intolerance, animus and discrimination."
The president's authority, the court said, "cannot go unchecked when, as here, the president wields it through an executive edict that stands to cause irreparable harm to individuals across this nation," Chief Judge Roger Gregory wrote.
Meanwhile, a three-judge panel of the 9th Circuit said Trump had not adhered to federal law in which Congress gives the president broad power in immigration matters.
The 9th Circuit opinion did not dwell on Trump's public comments, nor did it declare that the president had run afoul of the Constitution because his intent was to discriminate. Instead, the judges ruled that the travel ban lacked a sufficient national security or other justification that would make it legal, and that violated immigration law.
"There is no finding that present vetting standards are inadequate, and no finding that absent the improved vetting procedures there likely will be harm to our national interests," the judges wrote. "These identified reasons do not support the conclusion that the entry of nationals from the six designated countries would be harmful to our national interests."
They added that national security is not a " 'talismanic incantation' that, once invoked, can support any and all exercise of executive power."
In both appeals courts, a minority of conservative judges had said their colleagues were making a mistake. Judges should look only to whether the executive orders were proper on their face, they said, without trying to decide if the president had ulterior motives and defer to national security decisions made by the executive branch.
"The Supreme Court surely will shudder at the majority's adoption of this new rule that has no limits or bounds," wrote dissenting 4th Circuit Judge Paul Niemeyer.
Trump thundered on Twitter after the judicial setbacks that the second executive order was a "watered down version" of the first. And while his lawyers in court described the action as a temporary pause in immigration, and administration officials corrected reporters who called it a travel ban, Trump did not agree.
"People, the lawyers and the courts can call it whatever they want, but I am calling it what we need and what it is, a TRAVEL BAN!" he wrote.
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)
Get Breaking news, live coverage, and Latest News from India and around the world on NDTV.com. Catch all the Live TV action on NDTV 24x7 and NDTV India. Like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.