“Although this case has been moot since March, when the president rescinded the original executive order and issued a new one that does not restrict the entry of Iraqi nationals, the U.S. government has elected to settle this case on favorable terms,” Nicole Navas Oxman, a spokeswoman for the Justice Department, said in a statement.

The travel ban was an attempt to fulfill Mr. Trump’s campaign promise of a “total and complete shutdown of Muslims entering the United States.” The original version of the executive order imposing the ban was issued in January, barely a week after Mr. Trump’s inauguration. After that order was blocked in court, Mr. Trump issued a revised version, which will be the subject of arguments before the Supreme Court this fall.

The initial imposition of the ban was widely viewed as a political debacle for the young administration. John F. Kelly, who was secretary of Homeland Security at the time and is now the White House chief of staff, confirmed that he had not seen the final order until after the president signed it. The White House had not asked the department for a legal review. Some border control officials arrived at work the following morning still unsure how to interpret the president’s order.

Travelers from affected countries were already in the air on their way to the United States with valid visas when the executive order barring their entry was signed. Scores of refugees and immigrants found themselves trapped in airports across the country. Foreign students enrolled at American universities who had gone home for the winter holidays were blocked from returning. Legal permanent residents who had traveled for vacations or funerals were detained.

Hameed Khalid Darweesh, the first named plaintiff in the case, arrived at John F. Kennedy International Airport early in the evening, and watched his wife and three children pass successfully through passport control and customs and leave the arrivals area of the terminal, even as he was detained and held overnight and into the next day, much of the time in handcuffs. Mr. Darweesh, an Iraqi immigrant who had worked for the United States in his native country for years at great personal risk, became a symbol of the travel ban.