A federal judge in Brooklyn, New York issued an emergency ruling Saturday evening to prevent the deportation of travelers from seven Muslim-majority countries who have already entered the country, following President Donald Trump’s executive order on immigration.

The ruling will affect all those who landed at US airports Friday evening and Saturday, after Trump signed the order halting refugee arrivals into the US for 120 days, and barring citizens of Iraq, Iran, Sudan, Libya, Somalia, and Yemen for 90 days.

The ruling, a temporary emergency stay, now allows those who landed in the US and hold a valid visa to remain. Federal judges in Virginia, Massachusetts, and Washington also made emergency rulings on various aspects of the executive order.

The ACLU had filed a habeas corpus petition on behalf of two Iraqi refugees, who were detained by border agents at John F. Kennedy airport in New York City, despite having previously been granted asylum and holding valid visas. Both men were released Saturday.

“There is imminent danger that, absent the stay of removal, there will be substantial and irreparable injury to refugees, visa-holders, and other individuals from nations subject to the January 27, 2017, Executive Order,” US District Judge Ann Donnelly said in her ruling.

The court order will "not allow the government to remove anybody who has come and is caught up in the order nationwide. They cannot remove anybody," Lee Gelernt, deputy director of the ACLU's Immigrants' Rights Project, who argued the case, said in a video posted by the organization. "The key tonight was to make sure no one was put back on a plane."

Gelernt also said the court ordered the government to give the ACLU a list of names of the people who are being detained, and that "at a minimum" they will not be returned.

At the US District Court for the Eastern District of Virginia, Judge Leonie Brinkema ordered that "all legal permanent residents being detained at Dulles International Airport" be permitted to recieve access to lawyers, BuzzFeed's Chris Geidner reported. Brinkema also issued an order blocking for seven days the removal of any permanent residents being detained at Dulles International Airport, the Washington Post reported.

In Washington, US District Judge Thomas Zilly granted an emergency stay on the order to deport two unnamed individuals.

In Massachusetts, US District Judge Allison Burroughs andd Magistrate Judge Judith G. Dein ruled early Sunday morning for a stay expanded to lawful permanent US residents. The judges also ruled that people could not be detained, removed, or interrogated under the authority of the executive order, according to freelance reporter Joshua Eaton, who was at the courthouse.

The ACLU of Massachusetts, along with other immigration lawyers, filed the suit in federal court on behalf of two detained Iranian professors. Mazdak Pourabdollah Tootkaboni and Arghavan Louhghalam, two associate professors at the University of Massachusetts-Dartmouth who are both Iranian nationals and lawful permanent US residents were being detained at Logan Airport in Boston as of Saturday evening.

In a statement, ACLU executive director Anthony Romero slammed Trump for suffering "his first loss in court" in his first week in office.

"Clearly the judge understood the possibility for irreparable harm to hundreds of immigrants and lawful visitors to this country. Our courts today worked as they should as bulwarks against government abuse or unconstitutional policies and orders," Romero said.

Trump's order, signed Friday afternoon, had prompted widespread chaos at airports across the country as refugees and travelers were detained after arriving and denied entry.

The ACLU lawyers argued the order was "unconstitutional" and a "violation of international law."

Demonstrators outside the courthouse erupted in cheers as news of the stay spread.

"I hope Trump enjoys losing. He's going to lose so much we're going to get sick and tired of his losing," Faiz Shakir, the ACLU's national political director told Yahoo News.