(Reuters) - In a stinging rebuke to President Donald Trump, a U.S. appeals court refused on Thursday to reinstate his travel ban on people from six Muslim-majority nations, calling it discriminatory and setting the stage for a showdown in the Supreme Court.

The decision, written by Chief Judge Roger Gregory, described Trump’s executive order in forceful terms, saying it uses “vague words of national security, but in context drips with religious intolerance, animus, and discrimination.”

Attorney General Jeff Sessions said in a statement that the government, which says the temporary travel ban is needed to guard against terrorist attacks, would seek a review of the case at the Supreme Court.

“These clearly are very dangerous times and we need every available tool at our disposal to prevent terrorists from entering the United States and committing acts of bloodshed and violence,” said Michael Short, a White House spokesman.

MORE FROM REUTERS

* Kushner under FBI scrutiny in Russia probe: media reports

* Ireland looks set to elect gay premier in social, generational shift

* EXCLUSIVE: Kim Jong Un's 'rocket stars'

He added that the White House was confident the order would ultimately be upheld by the judiciary.

In its 10-3 ruling, the U.S. 4th Circuit Court of Appeals said those challenging the ban, including refugee groups and individuals, were likely to succeed on their claim that the order violates the U.S. Constitution’s bar against favoring one religion over another.

Gregory cited statements by Trump during the 2016 presidential election calling for a Muslim ban. During the race, Trump called for “a total and complete shutdown of Muslim’s entering the United States” in a statement on his website.

The judge wrote that a reasonable observer would likely conclude the order’s “primary purpose is to exclude persons from the United States on the basis of their religious beliefs.”

FILE PHOTO: A U.S. Customs and Border Protection arm patch and badge is seen at Los Angeles International Airport, California February 20, 2014. REUTERS/Kevork Djansezian/File Photo

The government had argued that the court should not take into account Trump’s comments on the campaign trail since they occurred before he took office on Jan. 20. But the appeals court rejected that view, saying they provide a window into the motivations for Trump’s action in government.

The appeals court questioned a government argument that the president has wide authority to halt the entry of people to the United States.

“Congress granted the President broad power to deny entry to aliens, but that power is not absolute. 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,” the majority opinion said.

The Virginia-based appeals court was reviewing a March ruling by Maryland-based federal judge Theodore Chuang that blocked part of Trump’s March 6 executive order barring people from Iran, Libya, Somalia, Sudan, Syria and Yemen for 90 days while the government put in place stricter visa screening.

A similar ruling against Trump’s policy from a Hawaii-based federal judge is still in place. That ruling went farther than Chuang’s order, blocking a section of the travel ban that also suspended refugee admissions for four months. The San Francisco-based 9th U.S. Circuit Court of Appeals is still reviewing that decision.

‘WOLF IN SHEEP’S CLOTHING’

Trump has lashed out at the judges and courts that have ruled against him, saying the 9th Circuit has a “terrible” record and calling its rulings on his policies “ridiculous.”

The March ban was Trump’s second effort to implement travel restrictions through an executive order. The first, issued on Jan. 27, led to chaos and protests at airports before it was blocked by courts.

The second order was intended to overcome the legal issues posed by the original ban, but it was blocked by judges before it could go into effect on March 16.

In an opinion that concurred with the majority on Thursday, Judge Stephanie Thacker wrote that the administration did nothing to distance itself from the first order, describing the revised ban as “the proverbial wolf in sheep’s clothing.”

Chief Judge Gregory, who wrote the majority opinion, was first installed in a recess appointment by Democratic President Bill Clinton and then nominated to the same post by Republican former president George W. Bush.

Nine other judges appointed by Democrats agreed to block the travel ban, while three Republican-appointed judges dissented.

“This to us is a complete win and overwhelming in terms of the votes,” said Omar Jadwat, director of the American Civil Liberties Union Immigrants’ Rights Project, who argued the case in the 4th Circuit.

The dissenting judges said the executive order was constitutional and a valid exercise of presidential authority, and that Trump’s campaign statements should not have come into play. The order itself “contains no reference to religion whatsoever,” Judge Paul Niemeyer wrote.

The White House also pointed to a dissent by Judge Dennis Shedd that said “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.”

Two other 4th Circuit judges, both appointed by Republicans, were recused from the case.