U.S. District Judge Ann Donnelly issued the emergency order after lawyers for the American Civil Liberties Union filed a court petition on behalf of people from seven predominantly Muslim nations who were detained at airports across the country as the ban took effect.
As the decision was announced, cheers broke out in crowds of demonstrators who had gathered at American airports and outside the Downtown Brooklyn courthouse where the ruling was issued.
The order barred U.S. border agents from removing anyone who arrived in the U.S. with a valid visa from Iraq, Syria, Iran, Sudan, Libya, Somalia and Yemen. It also covered anyone with an approved refugee application.
The ACLU believes the order also applies to what they estimate to be between 100 to 200 people currently facing at airports across the country. The judge set a court date for later in February to discuss further.
Refugees and immigrants were detained at JFK Airport and around the world Saturday because of President Trump's executive action on immigration. Now, the fallout of the order is causing chaos, confusion and massive protests.
One Iraqi man was released earlier Saturday, and the second was released later Saturday night.
The first Iraqi released, Hameed Khalid Darweesh had worked on behalf of the U.S. government in Iraq for 10 years, according to court papers filed in Downtown Brooklyn. Sources say the directive for the release appears to have come from the administration.
The second detainee, 33-year-old Haider Sameer Abdulkhaleq Alshawi, was coming to the United States to join his wife, who had worked for a U.S. contractor, and young son.
At an airport news conference, Darweesh was asked about his feelings toward Trump.
"I like him but this is a policy, I don't know,"he said. "He's the president, I'm a person. I have a special immigration visa in my passport because I work with the U.S. government, I support the U.S. government on the other side of the world. But when I came here, they say no and they treat me as I break the rules or do something wrong. That surprise me."
The men were detained after arriving overnight. Their immigration attorneys filed a writ of habeas corpus Saturday morning in the Eastern District of New York seeking to have their clients released.
At the same time, those attorneys filed a motion for class certification, to represent all refugees and immigrants.
Refugees in the air or on the way to the United States when the order was signed were being stopped and detained at airports, according to immigration advocates.
Seven U.S.-bound migrants - six from Iraq and one from Yemen - were prevented from boarding an EgyptAir flight to Kennedy airport.
Officials said the action Saturday by the airport was the first since President Trump imposed a three-month ban on refugees from seven Muslim-majority countries: Iraq, Syria, Iran, Sudan, Libya, Somalia and Yemen.
The officials said the seven migrants, escorted by officials from the U.N. refugee agency, were stopped from boarding the plane after authorities at Cairo airport contacted their counterparts in JFK airport.
The airlines flying from this part of the world are updating their travel advisories to reflect the situation.
KLM and Qatar Airways are indicating that green card holders or holders of diplomatic visas (A,G, C-2 or NATO,) from the seven countries are allowed to fly. Tourists and those on study visas are not.
It was a period of limbo for an unknown number of non-American citizens from Iraq, Syria, Iran, Sudan, Libya, Somalia or Yemen now barred from the country where they were studying or had lived, perhaps for years.
A federal law enforcement official who confirmed the temporary ban said there was an exemption for foreigners whose entry is in the U.S. national interest. It was not immediately clear how that exemption might be applied.
Trump's order exempts diplomats.
Those already in the U.S. with a visa or green card will be allowed to stay, according to the official, who wasn't authorized to publicly discuss the details of how Trump's order was being put in place and spoke only on condition of anonymity.
Customs and Border Protection was notifying airlines about passengers whose visas had been canceled or legal residents scheduled to fly back to the U.S. Airlines were being told to keep them off those flights.
(The Associated Press contributed to this report.)