President Trump’s political statements trailed him on Monday in court, where ­judges seemed skeptical his revised travel ban was based on national security concerns rather than his campaign promise to ban Muslims from entering the United States.

Thirteen judges on the U.S. Court of Appeals for the 4th Circuit were considering the case, and, during an extraordinary two-hour hearing, judge after judge asked acting solicitor general Jeffrey B. Wall about statements during the campaign and afterward in which Trump talked about a Muslim ban.

Wall said the order temporarily suspending foreign travelers from six majority Muslim countries was to protect the United States by reviewing the vetting of those who are potentially dangerous. That is not only within the president’s authority, Wall said, it is his responsibility.

But Judge Barbara Milano Keenan said that could mean a candidate for president could call for a Muslim ban every day for a year, enact a cleverly worded plan that accomplished that on his first day in office, and have courts ignore whether targeting Muslims was his real purpose.

The Trump administration’s new policy temporarily suspends the U.S. refugee program and blocks new visas to citizens of Iran, Libya, Somalia, Sudan, Syria and Yemen.

(Dalton Bennett/The Washington Post)

In March, a judge in Maryland and another in Hawaii halted enforcement of critical sections, pointing to comments by Trump and top advisers indicating that they wanted to bar Muslims from entry.

Under intense questioning, Wall acknowledged it could violate the Constitution to single out a religion for adverse treatment. But he said Trump’s revised executive order was neutral.

Judge Pamela Harris pressed Wall. “Clearly the law has a disparate impact on Muslims,” she said. “In what sense is it neutral?”

Wall pointed out that the ban did not affect Muslims from countries other than the six mentioned in the order, and said the Supreme Court has ruled in the past that in matters of immigration and national security, the president’s judgment is not open to judicial second-guessing.

“It is not a Muslim ban,” he said.

The 4th Circuit is considering whether to leave in place the Maryland decision siding with challengers who say the order violates First Amendment prohibitions on government condemnation of a particular religion.

To restore the administration’s policy in full, the Justice Department would have to win in Richmond and in its appeal of the Hawaii ruling, which is scheduled for argument on May 15 before the U.S. Court of Appeals for the 9th Circuit. The losing party in either case is likely to appeal to the Supreme Court.

A key issue for the court is whether judges should consider the rationale behind the policy beyond the language in the order itself. Many of the judges on Monday suggested they could not ignore the president’s previous statements. Three judges, all nominated to the bench by Democrats, directly quoted Trump’s remarks at the signing ceremony for the first travel ban in January.

Trump said at the signing that the order was for “the protection of the nation from foreign terrorist entry into the United States. We all know what that means.”

Judges Robert D. King, Henry F. Floyd and James A. Wynn Jr. referred to Trump’s remarks several times during the hearing.

“He’s never repudiated what he said about Muslims,” King said.

Several judges also asked whether a Trump campaign statement calling for a “total and complete shutdown of Muslims entering the United States” was still on his website.

The statement was brought up during a White House news briefing early Monday, and it appeared to have been removed as the courthearing in Richmond got underway.

In response to the judges’ questions, Wall said the meaning of Trump’s statements after taking office was “ambiguous” and that the court should defer to the president’s judgment when it comes to keeping the nation safe.

Keenan, however, repeatedly expressed doubts about the link between terrorism and foreign residents seeking travel visas from the six countries identified in the executive order.

What is it about their nationality, she asked, that “renders them suspect or renders them dangerous? I don’t see anything in the text that does that.”

Wall said the policy was designed to give the administration time to review the vetting procedures for granting visas from countries previously identified as areas of “concern” by Congress and the Obama administration.

“He’s not saying they are all dangerous,” Wall said of the Trump’s thinking. “He’s saying I’m not certain.”

The challenge in Maryland was brought by organizations and individuals, including a Muslim in the United States whose relative would be affected by the ban. They are being represented by the National Immigration Law Center and the American Civil Liberties Union.

Omar Jadwat, an attorney for the American Civil Liberties Union who is representing the challengers, struggled at times as he faced tough questioning, mostly by the Republican-nominated members of the court.

“Is the executive not entitled to some deference?” asked Judge Dennis W. Shedd.

Judge Paul V. Niemeyer was a particularly tough questioner, saying the president is charged with making national security decisions and that the president would be responsible if someone entering the country committed a terrorist act.

The judiciary is the third branch of government, Niemeyer noted: “Don’t we have some respect for the first branch, and the second branch?”

But Jadwat said the president is “not allowed to set a policy that violates the Establishment Clause,” referring to the Constitution’s command that government not favor one religion over another.

In a hypothetical, Jadwat speculated about how it would be perceived if a presidential candidate spoke of his dislike of Jews and, upon being elected, blocked travel from Israel because of a history of terrorist incidents there and the presence of a terrorist element in the country. The order might be neutral on its face, he said, but the intent would be clear.

Shedd asked whether Jadwat’s position would differ if Trump had repudiated his campaign remarks about Muslims.

“What if he says ‘sorry’ every day for a year,” Shedd quipped, drawing laughter from those seated in the courtroom.

“It’s possible that saying sorry isn’t enough,” Jadwat answered.

How quickly the 4th Circuit will rule is not known. But the court took the unusual step of bypassing the traditional three-judge panel and heard the case as a full group of 13. Two judges recused themselves: Allyson Kay Duncan, a George W. Bush nominee, and J. Harvie Wilkinson III, a Ronald Reagan nominee.

Barnes reported from Washington. Matt Zapotosky contributed to this report.