WASHINGTON (CNN) — A federal judge granted an emergency stay Saturday night for citizens of seven Muslim-majority countries who have already arrived in the US and those who are in transit, and who hold valid visas, ruling they can legally enter the US — a decision that halts President Donald Trump’s executive order barring citizens from those countries from entering the US for the next 90 days.

“The petitioners have a strong likelihood of success in establishing that the removal of the petitioner and other similarly situated violates their due process and equal protection guaranteed by the United States Constitution,” US District Judge Ann Donnelly wrote in her decision.

“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,” the ruling said.

The ACLU argued Saturday evening in a federal court in New York for a nationwide stay that would block the deportation of all people stranded in US airports under what the group called “President Trump’s new Muslim ban.”

The civil rights group is representing dozens of travelers held at John F. Kennedy International Airport Friday and Saturday, including two Iraqis with ties to the US military who had been granted visas to enter the United States.

The class-action lawsuit is the first legal challenge to Trump’s controversial executive order, which indefinitely suspends admissions for Syrian refugees and limits the flow of other refugees into the United States by instituting what the President has called “extreme vetting” of immigrants.

The two Iraqis, Hameed Khalid Darweesh and Haider Sameer Abdulkaleq Alshawi, had been released by Saturday night. But lawyers for other detained travelers said in a court filing that “dozens and dozens” of individuals remained held at JFK.

Trump’s order, signed Friday, bars travel from seven Muslim-majority countries, including Iraq, to the US for 90 days. It also suspends the US Refugee Admissions Program for 120 days until it is reinstated “only for nationals of countries for whom” members of Trump’s Cabinet deem can be properly vetted.

According to court papers, both Darweesh and Alshawi were legally allowed to come into the US but were detained in accordance with Trump’s order.

Darweesh, who worked as an interpreter for the US during the Iraq War, was released from detention early Saturday afternoon.

“America is the land of freedom,” he told reporters at the airport shortly after his release. “America is the greatest nation.”

A source with knowledge of the case confirmed Darweesh will be allowed into the US due to provisions in Trump’s order that allow the State and Homeland Security departments to admit individuals into the US on a case-by-case base for certain reasons, including when the person is already in transit and it would cause undue hardship and would not pose a threat to the security of the US.

The suit said Darweesh held a special immigrant visa, which he was granted the day of Trump’s inauguration on January 20, due to his work for the US government from 2003 to 2013.

Alshawi was released Saturday night, according to his attorney, Mark Doss.

Rep. Nydia Velazquez, D-New York, who had arrived at JFK by early Saturday afternoon to try and secure the release of the two Iraqis, railed against Trump’s order and pledged continued action.

“This should not happen in America,” Velazquez said following Darweesh’s release. “One by one, street by street, if we have to go to court, we will fight this anyplace, anywhere.”

‘The executive order is unlawful’

The lawsuit said the US granted Alshawi a visa earlier this month to meet with his wife and son, whom the US already granted refugee status for her association with the US military.

The lawyers for the two men called for a hearing because they maintain the detention of people with valid visas is illegal.

“Because the executive order is unlawful as applied to petitioners, their continued detention based solely on the executive order violates their Fifth Amendment procedural and substantive due process rights,” the lawyers argue in court papers.

Court papers said Customs and Border Protection authorities did not allow the lawyers to meet with the men and told them to try reaching Trump. Velázquez and fellow New York Democratic Rep. Jerrold Nadler said they attempted to speak to Darweesh and Alshawi at JFK’s Terminal 4 earlier Saturday but were denied.

“When Mr. Darweesh’s attorneys approached CBP requesting to speak with Mr. Darweesh, CBP indicated that they were not the ones to talk to about seeing their client. When the attorneys asked, ‘Who is the person to talk to?’ the CBP agents responded, ‘Mr. President. Call Mr. Trump,'” the court papers read.

Doss, an attorney with the International Refugee Assistance Project, told CNN his clients knew they had to get to the US as soon as possible so they boarded the first flight they could.

The two men had been allowed to make phone calls. They do not know each other, and it is unclear if they were held together or separately, or if they were kept in a holding cell, according to Doss.

“Our courageous plaintiff and countless others risked their lives helping US service members in Iraq. Trump’s order puts those who have helped us in harm’s way by denying them the safe harbor they have been promised in the United States,” said Karen Tumlin, the legal director of the NILC.

The lawsuit was earlier reported by The New York Times.

Legality questioned

Trump’s executive order, titled “Protection Of The Nation From Foreign Terrorist Entry Into The United States,” makes good on his longtime campaign promise to tighten borders and halt certain refugees from entering the United States.

The countries impacted are Iran, Iraq, Syria, Sudan, Libya, Yemen and Somalia, according to a White House official. It also caps the total number of refugees admitted into the United States during the 2017 fiscal year at 50,000, down more than half from the current level of 110,000.

“I am establishing new vetting measures to keep radical Islamic terrorists out of the United States of America,” Trump said during the signing at the Pentagon. “We don’t want them here.”

But the order immediately raised questions about its legal standing.

“What this order does is take people who played by the rules who have been rigorously vetted and slams the door of the country in their face because of their religion,” said David Leopold, an immigration attorney and the former president of the American Immigration Lawyers Association.

But Stephen Yale-Loehr, a professor of immigration law practice at Cornell Law School, said Trump’s order may have merit.

“The plaintiffs are alleging a variety of reasons why they should not be detained under the executive order. Their arguments include the equal protection clause of the Constitution and a provision in the immigration law that prohibits national origin discrimination,” Yale-Loehr said. “However, presidents have wide discretion on immigration, because immigration touches national sovereignty and foreign relations. Courts tend to defer to whatever a president declares on immigration. I think the administration could win.”

An administration official told CNN if a person has a valid visa to enter the US but is a citizen of one of the seven countries under the temporary travel ban, then the person cannot come into the US. If the person landed after the order was signed Friday afternoon, then the person would be detained and put back on a flight to their country of citizenship.

Separately, Department of Homeland Security officials acknowledged people who were in the air would be detained upon arrival and put back on a plane to their home country. An official was not able to provide numbers of how many have already been detained.

Progressives outraged

Democrats and liberal-leaning groups continued to denounce Trump’s order Saturday as racist.

“The first two refugees kept out of America by President Trump’s order are Iraqis who helped US troops survive during the war,” Rep. Jim Cooper, D-Tennessee, said on Twitter. “These men risked their lives for years to keep our troops safe. One was with the 101st Airborne. This is no way to treat our allies.”

Vermont Sen. Bernie Sanders called the action an “anti-Muslim order” that “plays into the hands of fanatics wishing to harm America.”

And Senate Minority Leader Chuck Schumer called on the Trump administration to “rescind these anti-American executive actions that will do absolutely nothing to improve our safety.”

Travelers turned away

Sarah Assali from Allentown, Pennsylvania, told CNN Saturday that the US government stopped six of her Syrian family members at Philadelphia International Airport and sent them back to Doha, Qatar, the origin city of their flight.

Assali said her family members were persecuted Christians and did not speak very good English, so they did not fully understand why they were being put on a plane back to the Middle East.

Additionally, some US-bound travelers who were either refugees or from countries specified in Trump’s executive ban have been turned back from Cairo International Airport, according to a Cairo airport official who is not authorized to speak to the media.

The official said they were required to follow the instructions of the United States in the matter. He said “(The airport personnel) have no choice but to follow orders. I don’t want to blame anyone here.”

CNN’s Kevin Bohn, Ellie Kaufman, Sheena Jones, Mohammed Tawfeeq, Rachel Crane, Chris Welch and Sarah Jorgensen contributed to this report.