Donald Trump lashed out at a temporary suspension of his executive order travel ban, warning: "The security of our nation is at stake."
The US federal appeals court unanimously upheld a suspension of the order that restricted travel from seven Muslim-majority countries.
Within minutes of the ruling, Trump reacted on Twitter:
Judges said the argument that the ban targets Muslims raised "serious allegations" and presented "significant constitutional questions", and agreed that courts could consider statements by Mr Trump and his advisers about wishing to enact such a ban.
Moments after Mr Trump's tweet, Washington governor Jay Inslee, a Democrat who leads one of the states that challenged the ban, said: "Mr President, we just saw you in court, and we beat you."
Speaking off camera, ITV News understands the President said: "It's a political decision and we're going to see them in court and I look forward to doing it.
"But it's a decision which we will win, in my opinion, very easily."
Mr Inslee said the decision "is a victory for Washington state and indeed the entire country."
He told MSNBC: "It means our system of checks and balances are intact and the Constitution and evidence is what counts in the courtroom rather than the number of tweets that you send out."
A final outcome will likely be determined by the US Supreme Court - but the appeals court said the government has not shown a likelihood it will succeed in appealing.
The appeals court said it acknowledged competing public interests for national security and free flow of travel.
But added that the government has not explained how the executive order could be administered - only in parts.
States offered evidence that even temporary reinstatement of the ban would "cause harm", the court added.
Mr Trump's executive order barred entry for citizens from Iran, Iraq, Libya, Somalia, Sudan, Syria and Yemen for 90 days.
He also imposed a 120-day halt on all refugees - except refugees from Syria who are barred indefinitely.
Critics have called the ban discriminatory against Muslims and have questioned its value as a security measure.
National security veterans, major US technology companies and law enforcement officials from more than a dozen states backed a legal effort against the ban.
Ultimately the courts will have to address questions about the extent of the president's power on matters of immigration and national security.
Traditionally, judges have been extremely cautious about stepping on the executive branch's authority in such matters, legal experts say.