The 10-3 decision from the 4th Circuit Court kept in place nationwide orders from two district judges that had blocked the president's revised decree. His order aimed to restrict new immigrants and travelers from six majority-Muslim nations.
All 10 judges in the majority were Democratic appointees. The three Republican appointees dissented.
Although the decision was another sweeping defeat for the president and his lawyers, it clears the way for them to take the issue to the Supreme Court, where a conservative majority gives them a better chance of prevailing. The procedural status of the case could allow the high court to hear at least a partial appeal rapidly, perhaps this spring.
In a statement, Atty. Gen.
"The President is not required to admit people from countries that sponsor or shelter terrorism, until he determines that they can be properly vetted and do not pose a security risk to the United States," Sessions said. "President Trump's executive order is well within his lawful authority to keep the nation safe."
Thursday's decision was the latest in which Trump's words formed the core of the case against him.
In issuing the limited travel ban, Trump said the temporary restrictions were needed because of the threat of terrorists arriving from countries including Libya, Somalia, Sudan and Yemen. The judges in the majority said they did not believe that was true purpose behind the executive order.
Trump's order "speaks with vague words of national security, but in context drips with religious intolerance, animus and discrimination," Chief Judge Roger L. Gregory wrote. He said the order conflicts with the 1st Amendment's ban on "laws respecting an establishment of religion."
"Congress granted the President broad power to deny entry to aliens, but that power is not absolute," he wrote. "It cannot go unchecked when, as here, the President wields it through an executive edict that stands to cause irreparable harm to individuals across this nation."
Much of Gregory's opinion recited statements from candidate Trump, including his call for a "total and complete shutdown of Muslims entering the United States" as well as comments since his election that blamed Muslims for the threat of terrorism.
Those "statements, taken together, provide direct, specific evidence of what motivated" the travel order, Gregory wrote: "President Trump's desire to exclude Muslims from the United States."
That impermissible motivation tainted both the original version of the order, which Trump issued during his first week in office, and a revised version issued in early March, the court said.
The three dissenters faulted the majority for ignoring Supreme Court rulings that called for deference to presidential authority over immigration.
Judge Paul Niemeyer, an appointee of President George H.W. Bush, also derided the majority for "fabricating a new proposition of law" that allows judges to use campaign statements to decide on the president's actions in office.
"The Supreme Court surely will shudder at the majority's adoption of this new rule that has no limits or bounds — one that transforms the majority's criticisms of a candidate's various campaign statements into a constitutional violation," he wrote.
He was equally scathing in accusing the majority of "radically extending" Supreme Court rulings on the Constitution's guarantee of religious freedom in ways that would limit the president's power over foreign affairs.
Omar Jadwat, the American Civil Liberties Union lawyer who argued the case, called the decision a victory for the Constitution. Its "prohibition on actions disfavoring or condemning any religion is a fundamental protection for all of us, and we can all be glad that the court today rejected the government's request to set that principle aside."
Trump initial travel ban caused chaos at airports around the nation and the world. It disrupted travel for thousands of people who live and work in the United States, including students, professors, tech executives and tourists.
It was quickly stopped by a federal judge in Seattle and by the 9th Circuit Court.
The president and his advisors retreated and issued a scaled-back order that applied only to foreigners who lived abroad and had yet to obtain a visa to come to the United States.
The revised order "does not bar entry of lawful permanent residents, dual citizens traveling under a passport issued by a non-banned country, asylees, or refugees already admitted to the United States," the appeals court noted.
That could have undercut the lawsuit, but Judge Gregory said at least one of the "John Doe" plaintiffs who challenged the order had standing to sue. The man is an Iranian national and a Muslim who is a lawful permanent resident of the United States, and he hopes to bring his Iranian wife to this country.
The revised order has run into the same legal problems as before, in part because of public declarations by Trump and White House officials that the new order was a "watered down" version of the original.
In addition to the judges in Maryland and Virginia who issued rulings against the revised travel order, a judge in Hawaii also blocked enforcement of it. That order is on appeal to the 9th Circuit.
In late January, when Trump signed his first order, his advisors said the new administration needed a temporary pause of 90 days, time enough to devise new and more extreme vetting procedures for travelers and refugees.
But little has been done to accomplish this goal. Jeffrey B. Wall, the acting solicitor general, told the appeals court that the nationwide injunction was so broad that officials were barred even from developing new procedures.
"We put down our pens," he said.
Trump's lawyers now could move quickly to the Supreme Court.
The two district judges who blocked enforcement of the travel ban did so on a preliminary basis without issuing a full ruling on the order's constitutionality. Because the order appeared to be unconstitutional and could do severe harm to the people who challenged it, the judges stopped it from taking effect pending a full hearing.
At this point, that procedural status means that the president's lawyers could file an emergency appeal with the high court. Rather than ask for a full hearing on the order's constitutionality, they could ask the justices to decide in the next few weeks whether to lift the nationwide injunctions.
On Twitter: DavidGSavage
3:55 p.m: This article was updated with additional detail on the court's ruling and reaction from the White House and others.