The American Civil Liberties Union took the Trump administration to federal court Saturday night over its new restrictions on immigrants and refugees coming to the U.S. — a policy many have linked to President Donald Trump's promised Muslim ban.

After about an hour of arguments in a New York City court, a judge granted a stay barring U.S. officials from deporting those detained in airports who have legal documents allowing them into the U.S. However, the stay does not wholly invalidate Trump's immigration restrictions or guarantee that all migrants won't be detained at airports.

The ACLU announced its victory over Twitter.

"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," Lee Gelernt, deputy director of the ACLU's Immigrants' Rights Project, said in a statement.

The civil rights advocacy group sued the president, the Department of Homeland Security and Customs and Border Patrol on behalf of Hameed Khalid Darweesh and Haider Sameer Abdulkhaleq Alshawi, two Iraqis who were detained by authorities at a New York City airport Friday evening.

"Because the executive order is unlawful as applied to [the] petitioners, their continued detention based solely on the executive order violates their Fifth Amendment procedural and substantive due process rights," ACLU lawyers wrote in a court petition filed Saturday.

U.S. District Court Judge Ann Donnelly granted the stay after determining there would be "substantial and irreparable injury to refugees, visa-holders and other individuals from nations subject to the Jan. 27, 2017, executive order," according to a court order.

"Our courts today worked as they should as bulwarks against government abuse or unconstitutional policies and orders," ACLU executive director Anthony Romero said in a statement. "On week one, Donald Trump suffered his first loss in court."

Thousands of protesters demonstrate outside of the international arrivals terminal at John F. Kennedy Airport in Queens, New York. Craig Ruttle/AP

On Friday, Trump barred migrants and travelers from seven Muslim-majority nations. He also halted the resettlement of refugees from war-torn Syria indefinitely, until "extreme vetting" measures could be implemented to ensure asylum seekers are not terrorists.

The hearing, which began at 7:30 p.m. Eastern, was taking place just a few miles from a massive protest at John F. Kennedy International Airport in southeast Queens. Several immigrants from countries included in Trump's executive order were reportedly detained by Customs and Border Patrol agents at JFK.

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

Jan. 29, 2017, 9 a.m. Eastern: This story has been updated.