Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

WASHINGTON — President Donald Trump's latest restriction on travel to the United States from a handful of mostly Muslim countries seemed likely to survive Supreme Court review, based on comments from the justices during an hour of animated courtroom argument on Wednesday.

The case is a critical legal test for a pillar of Trump's immigration policy, marking the first time the court has given a full hearing on one of Trump's first initiatives as president.

Solicitor General Noel Francisco emphasized that this third try at a travel ban is materially different from the first two, which were mostly rejected by lower courts.

"It was imposed after a worldwide review," he said, and was intended to identify high-risk countries whose citizens should largely be prevented from entering the country because of shortcomings in providing background on visa applicants or because the country involved is not effective in fighting terrorism.

"This isn't a so-called Muslim ban," he said, "because it excludes most of the Muslim world."

Justice Samuel Alito indicated that he agreed. "Why would a reasonable observer think it's a Muslim ban when it covers only 8 percent of the world's Muslim population?" he asked.

Trump's call during the campaign for a Muslim ban was raised by several members of the court, but Francisco said campaign statements shouldn't count, because they're made by a private citizen.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Justice Elena Kagan wondered what would happen if an anti-Semitic candidate was elected and called for a ban on immigration from Israel.

"I'm imagining an out-of-the-box kind of president in my example," she said, prompting laughter in the courtroom.

Francisco said such a ban would be allowed only if the government was concerned about some genuine national security threat from Israel.

Imposed last September by presidential proclamation, the latest version maintains limits on granting visas to travelers from five of the six countries covered by the original executive order — Iran, Libya, Somalia, Syria and Yemen. It lifts restrictions on visitors from Sudan and adds new limits on North Korea and Venezuela. Chad was part of the proclamation, but it was removed on April 10, after the White House said the country met enhanced visa security requirements.

The state of Hawaii, three of its residents and a Muslim American group challenged the new restrictions, and a federal judge blocked enforcement. The lawyer for the challengers, Neal Katyal, said the ban is illegal because it excludes people based on the country they come from, which Congress has banned.

Justice Sonia Sotomayor suggested that she was one of an apparent minority on the court prepared to find the president's action illegal. "Where does the president get this authority?" she asked.

But Chief Justice John Roberts said presidents must have the power to block immigration when faced with intelligence suggesting that an attack could come from a certain country. The current restriction, he suggested, is based on a similar kind of national security concern.

Justice Anthony Kennedy noted that Presidents Ronald Reagan and Jimmy Carter imposed countrywide bans on immigration. "This one is longer, more detailed," he said.

Katyal said Congress provided that such restrictions must be temporary, and Kennedy said the current one is subject to review every 180 days. "You want the president to say, 'I'm convinced that in six months we'll have a safe world?' " Kennedy said.

Francisco said the Constitution and federal laws give the president "broad authority to suspend or restrict the entry of aliens outside the United States when he deems it in the nation's interest."

While immigration law doesn't require the president to spell out detailed findings before he invokes the authority, the government says, the September proclamation "is more detailed as a matter of both process and substance than any prior order" limiting travel.

But the challengers said the law gives the president the power to ban only foreign nationals who share some characteristic making them harmful to admit to the U.S. In this case, Katyal said, "it bans the immigration of 150 million people who share nothing in common but nationality."

The first executive order on travel, announced Feb. 1, 2017, caused chaos at major airports when border officials refused to admit travelers who were in flight when the rules went into effect. It was quickly blocked by the courts. Enforcement of a revised travel ban, issued about a month later, was also stopped by lower court judges.

The Supreme Court allowed it to be enforced except for visa applicants with family or other close U.S. connections, but it expired before it was to be the subject of full-blown Supreme Court review.

The court will decide the case by late June.