Hundreds of people who gathered outside a Brooklyn courthouse Saturday night and hundreds more who had demonstrated throughout the day and into the evening at Kennedy Airport erupted into cheers as word spread that a federal judge had partially blocked President Donald Trump’s order for a 90-day ban on entry of non-U.S.-citizens from seven Muslim-majority countries.

The decision from U.S. District Court Judge Ann M. Donnelly, in a hastily called emergency hearing, capped a roller-coaster day that included protesters blocking roads at the airport and statements from civil liberties and Democratic officials that Trump’s policy is discriminatory and unAmerican.

The president’s action on Friday had prompted several organizations to join in filing suit early Saturday against him and federal agencies, seeking the release of two Iraqis detained at Kennedy Airport on Friday night because of the ban, and an injunction barring the detention of any migrant solely on the basis of Trump’s order and the release of those already detained.

Trump, in signing the executive order Friday afternoon, said he was helping to protect Americans from terrorists. On Saturday, he said the crackdown on those from Iraq, Iran, Libya, Somalia, Sudan, Syria and Yemen and refugees “is not a Muslim ban.”

But Rep. Nydia Velazquez, who with Rep. Jerrold Nadler helped secure the release early Saturday afternoon of one of the two Iraqis, Hameed Khalid Darweesh, said of Trump’s action, “What you have done is shameful.”

Velazquez, speaking before television cameras and reporters outside Terminal 4 at Kennedy, said, “I am begging you revisit this. It is ill-advised and tearing families apart . . . It will undermine the cooperation we need from Muslim countries to fight terrorism.”

advertisement | advertise on newsday

Darweesh, after arriving Friday on a flight from Iraq, was first interrogated for hours before he reached an attorney and his family, said Becca Heller, director of the International Refugee Assistance Project, which helped represent him.

Outside Terminal 4, he was reunited with his wife and children, who had traveled on the same flight and were released Friday night.

Darweesh had been granted a “special immigrant visa” last week, the lawsuit said, because he worked for the U.S. Army as an interpreter, for a federal agency as an engineer and for a federal contractor.

“The soul of America pushes me to leave my country and come here,” Darweesh said after he was released. “America is the land of freedom and the right. I’m very thankful . . . I have a special visa in my passport. I support the U.S. government, but they said they have a policy, and said I broke the rules.”

Darweesh said he handed over his passport, and customs officials put it in an envelope without explanation.

He left the airport terminal flanked by Velazquez, Nadler and immigration attorneys and was greeted by protesters chanting, “No ban! No wall! Donald Trump has got to fall!”

“They told me, ‘Don’t worry, this is America. There is a constitution, and I will be freed,’ ” Darweesh said. “When I get out, I was surprised.”

Nadler said Darweesh was “a marked man for his work with American troops, not a potential terrorist.”

advertisement | advertise on newsday

“This executive order is discriminatory on religion and quite disgusting,” Nadler said. “Not a single terror incident since 9/11 has been caused by any member of a country on the banned list.”

The other Iraqi, Haider Sameer Abdulkhaleq Alshawi, was granted a visa earlier this month to join his wife and son in the United States, the lawsuit said. They had been given refugee status because of the family’s association with the U.S. military. Heller said Alshawi was an interpreter and his wife, who is living in Houston, “was persecuted in Iraq for his work helping the U.S.”

The protest at Kennedy swelled to more than 2,000 demonstrators at its peak, with some protesters walking in the airport roadways at times and chanting.

Ladslav Leitner, 45, of the Bronx, held a sign that said “Impeach Trump, deport Melania,” who was born in Slovenia.

“I’m here to show how ridiculous the ideas from the White House are,” Leitner said. “It’s insane. He’s hurting immigrants and hurting asylum-seekers.”

advertisement | advertise on newsday

People arriving at the terminal threaded their way through the crush, as officers with the Port Authority Police and NYPD stood by. Mayor Bill de Blasio said he sent his commissioner of immigrant affairs to deliver coffee to the demonstrators, and filmmaker Michael Moore was among the crowd, using social media to rally support.

At one point, with the large number of people traveling to Kennedy, the Port Authority of New York and New Jersey suspended AirTrain service from Jamaica to the airport.

Newsha Mostafavi, 32, an Iranian-American born of immigrant parents, tried to join the protest, but was blocked when the AirTrain was shut down. She said her mother is living in Iran, and her father, a naturalized U.S. citizen, is barred by the Iranian government from returning there.

“We wanted to make our voices while we can,” Mostafavi said. “I’m frightened by the dismantling of the Constitution. This is how it started in Iran.”

Cuomo on Saturday night ordered the Port Authority to resume service.

“One of the fundamental rights that is granted to the people of this country is the right to peacefully protest,” he said in a statement.

With Matthew Chayes and Martin C. Evans.