Another US appeals court stomped on President Donald Trump’s revised travel ban, saying the administration violated federal immigration law and failed to provide a valid reason for keeping people from six mostly Muslim nations from coming.

The decision by a unanimous three-judge panel of the San Francisco-based Ninth US Circuit Court of Appeals helps keep the travel ban blocked and deals Trump a second big legal defeat on the policy in less than three weeks.

The administration has appealed another ruling against the ban to the Supreme Court, which is likely to consider the cases in tandem. The White House said it is confident the high court will uphold Trump’s executive order.

The Fourth US Circuit Court of Appeals in Virginia last month cited the president’s campaign statements calling for a “total and complete shutdown” on Muslims entering the US as evidence the 90-day ban was unconstitutionally “steeped in animus and directed at a single religious group”, rather than necessary for national security.

OPINION: The Muslim ban and the ethnic cleansing of America

The Ninth Circuit, which heard arguments in Seattle last month in Hawaii’s challenge to the ban, found no need to analyse Trump’s campaign statements. It ruled based on immigration law, not the Constitution.

“Immigration, even for the president, is not a one-person show,” the judges said. “National security is not a ‘talismanic incantation’ that, once invoked, can support any and all exercise of executive power.”

Judges Michael Hawkins, Ronald Gould and Richard Paez – all appointed by President Bill Clinton – said the travel ban violated immigration law by discriminating against people based on their nationality when it comes to issuing visas and by failing to demonstrate their entry would hurt American interests.

The president’s order did not tie citizens of Iran, Libya, Somalia, Sudan, Syria and Yemen to “terrorist organisations” or identify them as contributors to “active conflict”, the court said. It also did not provide any link between their nationality and their propensity to commit “terrorism”.

“In short, the order does not provide a rationale explaining why permitting entry of nationals from the six designated countries under current protocols would be detrimental to the interests of the United States,” the ruling said.

The judges pointed to a June 6 tweet by Trump saying the order was aimed at “dangerous countries”. That helped demonstrate he was not assessing whether the roughly 180 million citizens of the six countries had ties to “terrorism”, they said.

Because of the conflict with immigration law, the judges said they didn’t need to consider whether it also violated the Constitution’s prohibition on the government favouring or disfavouring any religion. The Fourth Circuit found the policy unconstitutional on that basis.

OPINION: Trump’s Muslim ban is a dangerous distraction

Attorney General Jeff Sessions denounced the ruling. “Recent attacks confirm that the threat to our nation is immediate and real. Certain countries shelter or sponsor terrorist groups like ISIS and al-Qaeda, and we may be unable to obtain any reliable background information on individuals from these war-torn, failed states,” Sessions said in a statement.

Trump also criticised the ruling on Twitter, saying it came at a “dangerous time” in history.

Well, as predicted, the 9th Circuit did it again – Ruled against the TRAVEL BAN at such a dangerous time in the history of our country. S.C. — Donald J. Trump (@realDonaldTrump) June 13, 2017

The White House predicted a win at the Supreme Court.

“Frankly, I think any lawyer worth their salt 100 percent agrees that the president’s fully within his rights and his responsibilities to do what is necessary to protect the country,” spokesman Sean Spicer said.

Hawaii Attorney General Douglas Chin said the new ruling proved that “our system of checks and balances, enshrined in the Constitution for more than 225 years, remains in place”.