America’s highest court also granted a White House request allowing part of its refugee ban to go into effect.
The justices said they would consider in October whether the president’s policy should be upheld or struck down.
Mr Trump seeks to place a 90-day ban on people from six mainly Muslim nations and a 120-day ban on refugees.
The president welcomed the ruling’s qualified authorisation to bar visitors from Iran, Libya, Somalia, Sudan, Syria and Yemen, which he described as “terror-prone countries”.
“As president, I cannot allow people into our country who want to do us harm,” he added.
Mr Trump has already said the ban would take effect within 72 hours of court approval.
What does the ruling say?
The Supreme Court said in Monday’s decision: “In practical terms, this means that [the executive order] 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.
“All other foreign nationals are subject to the provisions of [the executive order].”
The ruling also said it would permit a 120-day ban on all refugees entering the US to go into effect, allowing the government to bar entry to refugee claimants who do not have any “bona fide relationship” with an American individual or entity.
A Trump win – Anthony Zurcher, BBC News, Washington
Mark this down as a win for Donald Trump. The path to entry into the US for immigrants and refugees from the affected nations, if they don’t have existing ties to the US – either through family, schools or employment – just became considerably harder.
The decision marks a reaffirmation of the sweeping powers the president has traditionally been granted by the courts in areas of national security. There was fear in some quarters that the administration’s ham-fisted implementation of its immigration policy could do lasting damage to the president’s prerogatives. That appears not to be the case.
The government, the justices write, has a “compelling need to provide for the nation’s security”. That includes being able to close the borders based on an evaluation of the potential of foreign threats – at least for now.
The Supreme Court justices will fully consider the arguments on both sides next autumn. Of course, by that time it may not matter. The administration has three months to conduct its “executive review” of immigration policy and devise new guidelines.
In the meantime, the gates to America just got a bit smaller.
What does ‘bona fide’ relationship mean?
The ruling clarifies that those who would be deemed to have such a relationship would include a foreign national who wishes to enter the US to live with or visit a family member, a student at an American university, an employee of a US company, or a lecturer invited to address an American audience.
This would not apply, it said, to “someone who enters into a relationship simply to avoid [the executive order].
“For example, a non-profit group devoted to immigration issues may not contact foreign nationals from the designated countries, add them to client lists, and then secure their entry by claiming injury from their exclusion.”
Are there any divisions on the court?
Yes. Three of the court’s conservative justices – Clarence Thomas, Samuel Alito and Neil Gorsuch – wrote that they would have allowed the travel ban to go into full effect.
Justice Thomas said the government’s interest in preserving national security outweighs any hardship to people denied entry into the country.
Mr Trump restored a 5-4 conservative majority to the Supreme Court when his nominee, Justice Gorsuch, joined its bench in April.
There are five Republican appointees on the court and four Democratic appointees.
What did lower courts say?
The US president insisted his ban was necessary for national security amid a slew of terrorist attacks in Paris, London, Brussels, Berlin and other cities. However, critics called the policy un-American and Islamophobic, and the lower courts broadly seemed to agree.
The president’s policy was left in limbo after it was struck down by federal judges in Hawaii and Maryland days following its issuance on 6 March.
The 4th US Circuit Court of Appeals in Richmond, Virginia, said in May the ban was “rooted in religious animus” toward Muslims.
The San Francisco-based Ninth Circuit Court of Appeals said in June: “National security is not a ‘talismanic incantation’ that, once invoked, can support any and all exercise of executive power.”
Why did Trump revise the order?
The original ban, released on 27 January, provoked mass protests at American airports.
It included Iraq among nations whose travellers would be barred from the US, and imposed a full ban on refugees from Syria.
The president issued a revised version with a narrower scope on 6 March to overcome some of the legal problems.
But Mr Trump was unhappy about having to do so, calling it a “watered down, politically correct” version of the first one.