The US Supreme Court has partially lifted an injunction against President Donald Trump's travel ban.
America's highest court also granted an emergency request from the White House allowing part of the refugee ban to go into effect.
The justices said they would consider in October whether Mr Trump'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 Supreme Court said
in Monday's ruling: "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]."
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.
The court said it could not uphold lower court injunctions barring enforcement of the ban against foreigners who have no connection to the United States at all.
"Denying entry to such a foreign national does not burden any American party by reason of that party's relationship with the foreign national," the court said.
The ruling clarified 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."
The court also said it would allow 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.
Justices Clarence Thomas, Samuel Alito and Neil Gorsuch wrote in the dissenting ruling that they would have allowed the travel ban to go into full effect, pending a review.
The ruling hands a major victory to Mr Trump, who 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.
Mr Trump's policy had been left in limbo since it was struck down by federal judges in Hawaii and Maryland, who found it to be discriminatory.
Those lower courts ruled against the executive order days after the president issued a revised version with a narrower scope on 6 March.
The original ban, released on 27 January, provoked mass protests at American airports.
Omar Jadwat, who argued in a lower court against the government on behalf of the American Civil Liberties Union, urged the Supreme Court "to permanently strike it down".
"Courts have repeatedly blocked this indefensible and discriminatory ban," he said.
The president's revised order calls for a 90-day ban on travellers from Libya, Iran, Somalia, Sudan, Syria and Yemen. It also introduces a 120-day ban on all refugees entering the US to enable the government to implement stronger vetting procedures.
Mr Trump issued the orders amid a slew of terrorist attacks in Paris, London, Brussels, Berlin and other cities. However, critics called the policy un-American and Islamophobic.
The president was unhappy about the March order, calling it a "watered down, politically correct" version of the first one.
January's original executive order included Iraq among nations whose travellers would be barred from the US, and imposed a full ban on refugees from Syria.