In lifting the injunctions placed against the ban by lower courts, the Supreme Court 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.”

“But when it comes to refugees who lack any such connection to the United States, for the reasons we have set out, the balance tips in favor of the government’s compelling need to provide for the nation’s security,” the court wrote Monday.

The court wrote that a “close familial relationship is required” to fulfill the “bona fide relationship” standard.

Justices Clarence Thomas, Samuel Alito, and Neil Gorsuch, in a separate opinion, wrote that they would have allowed for the travel ban to go into effect either in full or with fewer restrictions than the court allowed.

Trump celebrated the high court’s decision, saying in a statement that it was a “clear victory for our national security” that would allow the travel suspension to “become largely effective.”

“As President, I cannot allow people into our country who want to do us harm,” he said. “I want people who can love the United States and all of its citizens, and who will be hardworking and productive.”

The executive order bars travel to the US by citizens from Libya, Iran, Yemen, Syria, Somalia, and Sudan. Green-card holders are exempt from the ban.

The order’s bans on travel from those countries, scheduled to last 90 days, and for all refugees, scheduled to last 120 days, are now allowed to take place with the court’s exceptions. The White House has claimed the temporary ban is needed so it can review its vetting process. It is possible the bans will be no longer active by the time the court is scheduled to hear the case. The court asked both parties to address whether the case would be moot by then.

On the campaign trail, Trump repeatedly called for a ban on entry to the US by all Muslims, and opponents of the ban have used Trump’s past statements to argue that the ban is intended to unconstitutionally target Muslims.

A previous version of the ban also barred entry from Iraqi citizens and did not include exceptions for those with green cards. It also provided a stricter standard for Syrian refugees and appeared to favor Christian refugees from Muslim-majority countries.

When the revised travel ban was announced in March, the White House said it would be implemented 10 days later. Last week, Trump said it would go into effect three days following approval by the Supreme Court. The initial travel ban’s sudden implementation led to mass chaos and protests at airports across the US.

The Department of Homeland Security said in a Monday statement that it will consult with the Department of Justice and the State Department before announcing details on the order’s implementation.

“The implementation of the executive order will be done professionally, with clear and sufficient public notice, particularly to potentially affected travelers, and in coordination with partners in the travel industry,” DHS said in the statement.

Earlier this month, Trump went on a lengthy tweetstorm in defense of the travel ban. Some proponents of the ban called out Trump’s tweeting, which they believed would hurt the executive order’s legal case. Sure enough, one of his tweets was later used against him in the 9th Circuit Court of Appeals’ ruling on the case.

“That’s right, we need a TRAVEL BAN for certain DANGEROUS countries, not some politically correct term that won’t help us protect our people!” Trump tweeted following a London terrorist attack.