A US judge has issued a stay temporarily halting the deportation of visa holders or refugees under an executive order from President Trump.
The American Civil Liberties Union (ACLU) filed a legal case early on Saturday in response to the order.
The judge’s stay prevents those “caught up” in the aftermath from being deported, the ACLU said.
The group estimates that between 100 and 200 people were being detained at airports or in transit.
The court decision came as thousands protested at airports in several US states over Donald Trump’s clamp down on immigration.
His executive order, signed on Friday, halted the entire US refugee programme and also instituted a 90-day travel ban for nationals from Iran, Iraq, Libya, Somalia, Sudan, Syria and Yemen.
Those who were already mid-flight were detained on arrival – even if they held valid visas or other immigration permits.
The ruling, from US District Judge Ann Donnelly, prevented the removal from the US of people with approved refugee applications, valid visas, and “other individuals… legally authorised to enter the United States”.
The emergency ruling also said there was a risk of “substantial and irreparable injury” to those affected.
Lee Gelernt, deputy legal director of the Immigrants Rights Project, argued the case in court and was greeted by a cheering crowd outside.
He said that some people had been threatened with being “put back on a plane” later on Saturday.
“The judge, in a nutshell, saw through what the government was doing and gave us what we wanted, which was to block the Trump order and not allow the government to remove anybody who has come and is caught up in the order, nationwide,” he told the crowd.
What does the ruling mean? By Nick Bryant, BBC New York correspondent
While Judge Ann Donnelly ordered that the refugees and others trapped at airports could not be sent back to their home countries, the ruling stopped short of allowing them into America.
Nor did she address the constitutionality of the highly controversial executive order. Those held at airports might now be kept in detention while the case is resolved. A hearing is scheduled for the end of next month.
The American Civil Liberties Union said the ruling proved that the courts were the bulwark of US democracy and that when Donald Trump enacted laws or executive orders that were unconstitutional or illegal, the courts would protect people’s rights. After just one week, it said, Donald Trump had suffered his first loss in court.
Mr Gelernt also said the judge had ordered the government to provide a list of names of those detained under the order.
“We are going to see each of the people, provide counsel, try and get them out of detention right now – but at minimum, they will not be returned back to danger,” Mr Gelernt said.
The court has set a date to hear the case for the end of February.
Speaking earlier on Saturday, Mr Trump defended his executive order, saying it was “not a Muslim ban”.
“It’s working out very nicely. You see it at the airports, you see it all over,” Mr Trump told reporters at the Oval Office.
“This is a remarkable day,” said the ACLU’s executive director, Anthony Romero.
“What we’ve shown today is that the courts can work … they’re a bulwark in our democracy, and when President Trump enacts laws or executive orders that are unconstitutional and illegal, the courts are there to protect everyone’s rights.”
Mr Romero said the executive order was “un-American” and that “flew in the face of established statutes that we have long regarded in this country.”
In addition to those detained on arrival in the US, some air passengers were prevented from boarding US-bound flights after the order was signed.
On Saturday five Iraqi passengers and a Yemeni national were prevented from boarding a flight at Cairo airport bound for New York.
Dutch airline KLM said it had turned away seven people who were booked on to its flights into the US because they would no longer have been accepted
The restriction applies to dual nationals – so, for example, a British citizen who is also a citizen of Iran would not be able to enter the US.