The district judges, both appointed by President Barack Obama, had ruled against an earlier attempt at a travel ban, as had the federal appellate courts for their regions of the country, and the appeals were consolidated and taken up by the Supreme Court, which allowed some parts of the ban to go into effect, pending consideration of the case. That became moot after Mr. Trump issued a revised ban last month. The new version was the one blocked by the two judges this week, and with the same issues still in play, the high court appears likely to consider the matter again.

In response to Wednesday’s ruling, a Justice Department spokesman, Ian Prior, referred to his statement the day before: “Today’s ruling is incorrect, fails to properly respect the separation of powers, and has the potential to cause serious negative consequences for our national security.”

The cases have presented the rare spectacle of a president’s own words undercutting the legal arguments of his administration. The government’s position is that the latest ban, like those before it, is not an attempt to prevent Muslims from entering the United States, but a bid to limit and control who enters from some of the world’s most dangerous countries.

Judge Chuang quoted extensively from Mr. Trump’s statements and Twitter messages during the campaign and in office, including his demand as a candidate for “a complete and total shutdown of Muslims entering the United States,” his calls for “a Muslim ban,” and a remark that because his statements had upset some people, he was “talking territory instead of Muslim.”

The Trump administration has insisted that the travel bans were motivated by security concerns, not religious animus, but courts have found otherwise. The most recent version of a ban, the third one issued by the president, differs from the previous ones, but not enough to make the case that the motive behind it has changed, Judge Chuang found.