NEW YORK ― Late Saturday night, a federal judge in Brooklyn temporarily halted parts of President Donald Trump’s sweeping executive order that aimed to block the entry of Syrian refugees and impose a de facto ban on travelers coming from several Muslim-majority countries.

The American Civil Liberties Union, immigrants’ rights groups and refugee relief organizations had filed the action in federal court Saturday morning on behalf of two Iraqi nationals who were detained at John F. Kennedy International Airport in New York City, asking for a declaration that the order is unconstitutional and requesting an injunction to prevent its implementation against other travelers who may be equally harmed.

“The petitioners have a strong likelihood of success in establishing that the removal of the petitioners and others similarly situated violates the rights to Due Process and Equal Protection guaranteed by the United States Constitution,” U.S. District Judge Ann Donnelly of the Eastern District of New York wrote in her order.

The legal action named Trump in his official capacity as president, as well as the Department of Homeland Security and other high-ranking officials. Although temporary and subject to appeal, it represents the first major constitutional setback faced by the new administration.

“This ruling preserves the status quo and ensures that people who have been granted permission to be in this country are not illegally removed off U.S. soil,” said Lee Gelernt, the ACLU lawyer who was in court Saturday arguing the case, in a statement.

Signed judge's order. No refugees are going to be immediately deported pic.twitter.com/sbfaG7DBt0 — ACLU National (@ACLU) January 29, 2017

The immediate reading of Donnelly’s order left several interpretations, but the nationwide stay specifically forbids the federal government from deporting refugees who have been cleared by immigration authorities to enter the country. It also protects “holders of valid immigrant and non-immigrant visas, and other individuals from Iraq, Syria, Iran, Sudan, Libya, Somalia, and Yemen, [who are] legally authorized to enter the United States.”

Because the Constitution only applies territorially, that would mean the ruling covers those travelers detained and stranded at airports and other ports of entry, and possibly those who were stranded mid-travel but have authorization to be in the United States.

The initial ambiguity of Saturday’s ruling underscores the crazed process by which Trump’s executive order was implemented and litigated ― all within a span of a day. And it portends even more high-pitched court battles ahead, including a likely trip to the Supreme Court, which is presently short one member.

The ACLU notched another temporary victory in Massachusetts in the hours after midnight Sunday, when two federal judges there decreed that travelers who are legally authorized to be in the United States shouldn’t be detained at or deported from Logan International Airport for a period of seven days.

Protesters cheer as laywers emerge from a Brooklyn court after a judge blocks the Trump immigration order https://t.co/djFvNiHjhj pic.twitter.com/zRYX8ZtNUc — NBC New York (@NBCNewYork) January 29, 2017

“Customs and Border Protection shall notify airlines that have flights arriving at Logan Airport of this [court] order and the fact that individuals on these flights will not be detained or returned based solely on the basis of the Executive Order,” read the ruling signed by U.S. District Judge Allison Burroughs and U.S. Magistrate Judge Judith Gail Dein.

Earlier on Saturday, Trump told reporters at the White House that his executive order was “working out very nicely.”

“You see it at the airports, you see it all over,” he said.

But hours after the court’s ruling, the Trump administration had yet to comment or tweet about it. The White House has been under mounting scrutiny over how Trump’s slapdash travel ban ― which has sown chaos and sparked protests at airports across the country ― came to be.

One CNN report indicated that the White House didn’t consult with the Office of Legal Counsel, the Department of Justice component that advises the executive branch on policy, prior to Trump’s signing of the order on Friday. And two of Trump’s closest advisers, Steve Bannon and Stephen Miller, reportedly overruled Department of Homeland Security officials who had concluded that the executive order shouldn’t bar legal permanent residents from the affected countries from entering the U.S.

One of the two Iraqis’ at the center of the legal action against the travel ban, Hameed Khalid Darweesh, was released shortly after noon on Saturday. The other man, Sameer Abdulkhaleq Alshawi, was released moments after the court ruling.

In related developments Saturday evening, federal judges in Virginia and Seattle issued orders temporarily barring the deportation of travelers stranded in their jurisdictions.

In Virginia, U.S. District Judge Leonie Brinkema allowed between 50 and 60 legal permanent residents detained at Washington Dulles International Airport to contact lawyers and family members, and halted their deportations for seven days. Federal authorities detained the travelers upon arrival because they are citizens of the seven countries listed in Trump’s travel ban.

And in Seattle, U.S. District Judge Thomas Zilly halted the deportation of two travelers who had sought a declaration that their detentions were illegal. The judge set a hearing for next week to determine the next steps in the case.

In a terse statement released early Sunday morning, DHS said that it would comply with the spat of court orders, but emphasized that it would continue to enforce its national security priorities under Trump’s executive directive. The agency also downplayed the effect the order has had on thousands of travelers.

“No foreign national in a foreign land, without ties to the United States, has any unfettered right to demand entry into the United States or to demand immigration benefits in the United States,” the statement read.

Read the full ruling blocking parts of Trump’s executive order below:

Stay of Executive Order Banning Syrian Refugees and Other Travel 01-28-2017 on Scribd

This article has been updated with the ruling in Massachusetts and a comment from DHS.