The ruling is the most bruising the White House has suffered in its attempts to defend the ban, as it was rendered by 13 judges on the U.S. Court of Appeals for the 4th Circuit — which deemed the case important enough to skip the usual three-judge process that the vast majority of cases go through.

U.S. Chief Circuit Judge Roger Gregory wrote that the text of Trump’s executive order, which was challenged in courts across the country for targeting members of a particular faith, “speaks with vague words of national security, but in context drips with religious intolerance, animus, and discrimination.”

“Congress granted the President broad power to deny entry to aliens, but that power is not absolute,” Gregory wrote in a ruling that largely upheld the original block on the travel ban. “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.”

Ten of the judges who heard the case, all of them appointed by Democratic presidents, voted to keep Trump’s travel restrictions on hold. Of the 10, Gregory had the court’s majority decision and four of his colleagues issued individual opinions that offered different grounds, some narrower than others, for concluding that the travel ban is likely invalid under immigration law and the Constitution.

“Laid bare, this Executive Order is no more than what the President promised before and after his election: naked invidious discrimination against Muslims,” wrote U.S. Circuit Judge James Wynn in a concurrence. “Such discrimination contravenes the authority Congress delegated to the President in the Immigration and Nationality Act ... and it is unconstitutional under the Establishment Clause.”

The three dissenting judges, all Republican appointees, wrote separate opinions condemning the ruling, each offering different reasons why Trump’s executive order is lawful. One of them, U.S. Circuit Judge Dennis Shedd, lamented “the larger ramifications of this decision” for the nation’s safety.

“Regrettably, at the end of the day, the real losers in this case are the millions of individual Americans whose security is threatened on a daily basis by those who seek to do us harm,” Shedd wrote.

The decision clears the way for Trump to appeal to the Supreme Court, a move he promised when the first version of the travel ban was shot down. The appeal never materialized then — the administration chose instead to start from scratch and reissue a tamer version of the executive order.

The watered-down version — which removed Iraq from the list of barred countries and eliminated the ban on Syrian refugees — no longer applied to permanent residents and had a delayed rollout, all in hopes of avoiding the detentions, chaos and protests unleashed by the first order.

These tweaks were intended to make the travel ban more palatable to the courts. But Trump’s campaign promises and anti-Muslim sentiment kept dogging the administration, and federal judges in Hawaii and Maryland couldn’t help but take that history into account in assessing the travel ban’s legality. Both courts concluded that Trump’s own words, and those of his surrogates, tainted the executive order with unconstitutional animus against a religious group.

And the 4th Circuit went right along.

“We cannot shut our eyes to such evidence when it stares us in the face, for there’s none so blind as they that won’t see,” Gregory wrote. “If and when future courts are confronted with campaign or other statements proffered as evidence of governmental purpose, those courts must similarly determine, on a case-by-case basis, whether such statements are probative evidence of governmental purpose.”

Not every judge in the majority agreed with that conclusion, even if they agreed that Trump’s executive order likely violates the Constitution’s establishment clause, which forbids the government from expressing religious preferences.

For example, U.S. Circuit Judge Stephanie Thacker, an Obama appointee, said that as a candidate, Trump had yet to take an “oath to preserve, protect and defend the Constitution,” and thus was at liberty to make wild campaign promises. But once he took office, everything he or his administration said or did was fair game.

“Once a candidate becomes President, however, the Constitution vests that individual with the awesome power of the executive office while simultaneously imposing constraints on that power,” Thacker wrote.

The Trump administration, for its part, has insisted that the president’s words shouldn’t be used against him, and that courts should be careful not to look behind the chief executive’s motives or second-guess his broad authority to set immigration policy.

“The order before this court has been the subject of a heated and passionate political debate,” a Department of Justice lawyer said during oral arguments before the 4th Circuit. “But the precedent set by this case for this court’s role in reviewing the president’s power at the borders will long transcend this debate and this order and this constitutional moment.”

Indeed, U.S. Circuit Judge Paul Niemeyer, a conservative, warned that the 4th Circuit’s focus on Trump’s past statements was creating a “new rule” unsupported by prior precedents ― all but telegraphing to the Supreme Court that they should correct the error. Anything less, he said, would give future plaintiffs “a sword” to wield religious challenges to government action, and may leave Trump powerless to implement similar executive orders at all.

“Government officials will avoid speaking about religion, even privately, lest a court discover statements that could be used to ascribe a religious motivation to their future actions,” Niemeyer wrote. “And, in the more immediate future, our courts will be faced with the unworkable task of determining when this President’s supposed religious motive has sufficiently dissipated so as to allow executive action toward these or other majority-Muslim countries.”

The next stop for the case, as Trump has often boasted, is the Supreme Court itself. And when that happens, it is not an understatement to say the dispute will set up one of the biggest presidential showdowns the justices will decide in modern history.

UPDATE: 5:40 p.m. ― Attorney General Jeff Sessions said in a statement on Thursday evening that the Justice Department “will seek review of this case in the United States Supreme Court.”

Sessions said Trump’s order was “well within his lawful authority to keep the Nation safe” and that DOJ “strongly disagrees with the decision of the divided court, which blocks the President’s efforts to strengthen this country’s national security.”

“As the dissenting judges explained, the executive order is a constitutional exercise of the President’s duty to protect our communities from terrorism,” Sessions said. “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.”

Ryan J. Reilly contributed to this story.