Demonstrators rally in New York on Thursday during a small protest of President Trump’s travel ban and suspension of the country's refugee program. (Drew Angerer/Getty Images)

The Trump administration filed court papers Friday hoping to salvage its second version of a travel ban after two judges in separate cases this week found that it probably violated the Constitution.

The Justice Department filed papers in federal court in Maryland, setting up a new legal showdown in the U.S. Court of Appeals for the 4th Circuit, located in Richmond.

This week, federal judges in Hawaii and Maryland issued orders against the travel ban, finding that it violated the First Amendment by disfavoring a particular religion. If the Justice Department had appealed the Hawaii order, the case would have gone to the same San Francisco-based appeals court that rejected an earlier version of the travel ban.

William Jay, a former Justice Department lawyer specializing in appellate cases, said the government may have a very simple reason for challenging the Maryland case first: The judge there issued a preliminary injunction, which is more easily appealed in federal courts than temporary restraining orders like the one issued in Hawaii.

There may be another strategic reason to challenge the Maryland case first, said University of Richmond law professor Kevin Walsh.

In Richmond, Walsh said, “the government has the benefit of a fresh set of eyes, unclouded by a precedent of the prior order.”

He added that a ruling reversing the Maryland injunction could “cast doubt on the enforceability in the 4th Circuit of the Hawaii judge’s order that purports to reach nationwide.’’

But Walsh cautioned that if the administration were to win its case in Richmond, that could, at least in theory, set up a confusing situation in which the travel ban was enforced in one part of the country but not another.

Critics of the executive order call it an attempt to fulfill President Trump’s campaign promise to temporarily ban Muslims from entering the United States. The administration denies it is a Muslim ban and says the order aims to prevent terrorism by blocking visitors from terror-prone countries where screening of individuals seeking U.S. visas may not be effective.

Omar Jadwat, an ACLU lawyer representing plaintiffs in the Maryland case, said that the president’s executive order “has fared miserably in the courts, and for good reason — it violates fundamental provisions of our Constitution. We look forward to defending this careful and well-reasoned decision in the appeals court.’’

The U.S. Court of Appeals for the 9th Circuit, based in San Francisco, ruled against the first version of Trump’s executive order suspending the U.S. refugee program and temporarily barring visitors from seven majority-Muslim countries: Libya, Iran, Iraq, Sudan, Somalia, Syria and Yemen. A three-judge panel found that executive order violated the due process rights of people who had previously been approved to visit the United States.

In response to the legal setback, the White House crafted a new version that dropped Iraq from the list of countries and exempted holders of valid visas and green cards.

(Bastien Inzaurralde/The Washington Post)

But the new version also quickly ran afoul of the courts.

In Hawaii, U.S. District Judge Derrick K. Watson’s 43-page ruling used the public statements of the president and his senior advisers to conclude that there was a “strong likelihood of success’’ that opponents of the travel ban would be able to prove it violates the Constitution.

The First Amendment prohibits any “law respecting an establishment of religion,” meaning the government must remain neutral among religions — or between religions and nonreligion — and not favor or disfavor a particular faith.

“A reasonable, objective observer — enlightened by the specific historical context, contemporaneous public statements, and specific sequence of events leading to its issuance — would conclude that the Executive Order was issued with a purpose to disfavor a particular religion,” Watson wrote.

Trump, speaking at a rally in Nashville shortly after the judge’s decision, insisted he would not back down. “We’re going to fight this terrible ruling,” he said, to applause from the crowd. “We’re going to take our case as far as it needs to go, including all the way up to the Supreme Court.”

The second version of the travel ban “is a watered-down version of the first one,” the president said. “And let me tell you something. I think we ought to go back to the first one and go all the way, which is what I wanted to do in the first place.”

The Justice Department has said it will continue to defend the president’s order in court.

In the Maryland case, U.S. District Judge Theodore D. Chuang wrote that the origins of the travel ban suggest that religious screening, not national security, was the primary purpose.

“The fact that the White House took the highly irregular step of first introducing the travel ban without receiving the input and judgment of the relevant national security agencies strongly suggests that the religious purpose was primary, and the national security purpose, even if legitimate, is a secondary post hoc rationale,’’ the judge wrote.

Read more:

7 things Trump and his advisers have said about the travel ban that wound up hurting them in court

Trump and his advisers can’t keep quiet — and it’s becoming a real problem