Donald Trump's team has vowed to take the fight over his controversial travel ban to the US Supreme Court after a federal appeals court ruled against the executive order targeting six Muslim-majority countries.
In a 10-3 vote, the 4th US Circuit Court of Appeals said the revised travel ban "speaks with vague words of national security, but in context drips with religious intolerance, animus and discrimination", and probably violates the constitution.
It upheld a lower court ruling that blocks the Republican administration from cutting off visas for people from Iran, Libya, Somalia, Sudan, Syria and Yemen.
The 4th Circuit is the first appeals court to rule on the revised travel ban unveiled in March.
Mr Trump's administration had hoped it would avoid the legal problems the first version from January encountered.
A second appeals court, the 9th US Circuit based in San Francisco, is also weighing the revised travel ban after a federal judge in Hawaii blocked it.
The Supreme Court would almost certainly step into the case if asked. The justices almost always have the final say when a lower court strikes down a federal law or presidential action.
Mr Trump could try to persuade the Supreme Court to allow the policy to take effect, even while the justices weigh whether to hear the case, by arguing that the court orders blocking the ban make the country less safe.
If the administration does ask the court to step in, the justices' first vote could signal the court's ultimate decision.
A central question in the case before the 4th Circuit was whether courts should consider Mr Trump's public statements about wanting to bar Muslims from entering the country as evidence that the policy was primarily motivated by the religion.
His administration argued the court should not look beyond the text of the executive order, which does not mention religion.
The countries were not chosen because they are predominantly Muslim but because they present terrorism risks, the administration said.
Chief Judge Roger L Gregory wrote that the government's "asserted national security interest ... appears to be a post hoc, secondary justification for an executive action rooted in religious animus and intended to bar Muslims from this country".
Attorney general Jeff Sessions said the court's ruling blocks Mr Trump's "efforts to strengthen this country's national security".
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 threat, Mr Sessions said.