High-level U.S. government officials including former attorney general John D. Ashcroft and former FBI director Robert S. Mueller III cannot be held liable for the alleged unconstitutional treatment of noncitizens detained after the terrorist attacks of Sept. 11, 2001, the Supreme Court ruled Monday.

The court in a shorthanded 4-to-2 decision ended a long-running lawsuit filed against former officials in the administration of President George W. Bush for actions following the attacks on the World Trade Center and the Pentagon. Hundreds of Arab and South Asian men — many of them Muslim — were arrested and detained as part of a nationwide terrorism investigation.

Six plaintiffs brought a representative suit, brought on behalf of those rounded up, who were noncitizens and lacked lawful immigration status. They alleged they were held because of their race, religion, ethnicity, and national heritage and immigration status, and were subjected to verbal and physical abuse, daily strip searches and months in solitary confinement. None of those held at the detention center in Brooklyn were found to have any connection to terrorism.

Justice Anthony M. Kennedy said that the treatment alleged by the men was “tragic,” but that the U.S. Court of Appeals for the 2nd Circuit in New York was wrong to let the suit proceed. In general, government officials are shielded from civil lawsuits when they have acted in good faith in carrying out their duties.

Kennedy acknowledged competing concerns.

Without lawsuits holding public officials accountable, he said, “there will be insufficient deterrence to prevent officers from violating the Constitution.” On the other hand, if such lawsuits were allowed, “high officers who face personal liability for damages might refrain from taking urgent and lawful action in a time of crisis.”

“There is therefore a balance to be struck, in situations like this one, between deterring constitutional violations and freeing high officials to make the lawful decisions necessary to protect the nation in times of great peril,” Kennedy said, before concluding:

“The proper balance is one for the Congress, not the Judiciary, to undertake.”

His opinion was joined by Chief Justice John G. Roberts Jr. and Justices Clarence Thomas and Samuel A. Alito Jr.

The court was particularly shorthanded. Justices Sonia Sotomayor and Elena Kagan recused themselves, presumably because each had worked on the case before joining the court. New Justice Neil M. Gorsuch took no part in the case because it was argued before he was confirmed to the court.

Justices Ruth Bader Ginsburg and Stephen G. Breyer dissented, and Breyer underscored the importance of the case by reading part of his dissent from the bench.

He said he was most concerned by the majority’s view that “post 9/11 circumstance — the national security emergency — does or might well constitute a ‘special factor’ precluding lawsuits.”

“History tells us of far too many instances where the executive or legislative branch took actions during time of war that, on later examination, turned out unnecessarily and unreasonably to have deprived American citizens of basic constitutional rights,” Breyer wrote in the dissent Ginsburg joined.

There were three cases, including Ziglar v. Abbasi.

Justices rule for Ala. inmate

The Supreme Court sided Monday with an Alabama death row inmate who said he was denied a mental health expert who would help him fight the state’s attempt to sentence him to death.

The justices had taken the case to shed more light on a previous decision that poor defendants whose mental health might explain their criminal actions have a right to expert evaluation. The question was whether that expert should be on the defendant’s side, not just neutral.

But much to the consternation of the dissenting justices, the five-member majority in Monday’s case ruled that Alabama’s treatment of James McWilliams, who was sentenced to death in 1986, did not meet even the previous standard.

There is no need to “issue a sweeping ruling when a narrow one will do,” wrote Breyer, who was joined by Kennedy, Ginsburg, Sotomayor and Kagan.

McWilliams was convicted of the 1984 rape, robbery and murder of convenience store clerk Patricia Vallery Reynolds in Tuscaloosa, Ala. Before sentencing, a state psychologist who examined McWilliams said he had “organic brain damage” and records showed he had received psychotropic drugs in prison.

But all of that came just two days before sentencing, and defense lawyers requested a delay and professional help in deciphering what that meant for McWilliams’s case.

The judge refused and sentenced McWilliams to death.

McWilliams’s lawyer at the Supreme Court, Stephen Bright, said the majority recognized that “Alabama’s provision of mental health assistance fell dramatically short of what the Constitution requires.”

The case will go back to lower courts for more work.

Dissenting justices accused the majority of “a most unseemly maneuver,” in the words of Alito.

“The court declines to decide the question on which we granted review and thus leaves in place conflicting lower court decisions regarding the meaning of a 32-year-old precedent,” Alito wrote. He was joined by Roberts, Thomas and Gorsuch.

Most states now provide the independent expert McWilliams sought, but the Arkansas Supreme Court recently stayed the execution of two men on its death row because of a similar issue.

The case is McWilliams v. Dunn.