WASHINGTON — A federal judge in Brooklyn came to the aid of scores of refugees and others who were trapped at airports across the United States on Saturday after an executive order signed by President Trump, which sought to keep many foreigners from entering the country, led to chaotic scenes across the globe.

The judge’s ruling blocked part of the president’s actions, preventing the government from deporting some arrivals who found themselves ensnared by the presidential order. But it stopped short of letting them into the country or issuing a broader ruling on the constitutionality of Mr. Trump’s actions.

The high-stakes legal case played out on Saturday amid global turmoil, as the executive order signed by the president slammed shut the borders of the United States for an Iranian scientist headed to a lab in Massachusetts, a Syrian refugee family headed to a new life in Ohio and countless others across the world.

The president’s order, enacted with the stroke of a pen at 4:42 p.m. Friday, suspended entry of all refugees to the United States for 120 days, barred Syrian refugees indefinitely, and blocked entry into the United States for 90 days for citizens of seven predominantly Muslim countries: Iran, Iraq, Libya, Somalia, Sudan, Syria and Yemen.