Former attorney general John D. Ashcroft cannot be sued personally for allegedly misusing his power to detain an American Muslim in the post-Sept. 11, 2001, crackdown on suspected terrorists, the Supreme Court ruled unanimously Tuesday.

But the decision exposed sharp differences among the justices about whether the government went too far when it used a statute meant to ensure that witnesses show up for trial. Civil libertarians alleged that the government used the statute to imprison those whom it suspected, but could not prove, had committed a crime.

The court has long protected government officials from personal liability for their official actions unless it can be shown that they have violated a person’s constitutional rights and that the right was “clearly established” at the time of the conduct.

Justice Antonin Scalia said that was not the case when Ashcroft and the Justice Department used the federal “material witness” statute to detain Abdullah al-Kidd, a U.S. citizen, in a terrorism investigation. Kidd neither testified in a trial nor was charged with a crime, but he was treated as a criminal suspect during his more than two weeks of detention.

“Qualified immunity gives government officials breathing room to make reasonable but mistaken judgments about open legal questions,” Scalia wrote. “When properly applied it protects all but the plainly incompetent or those who knowingly violate the law.

“Ashcroft deserves neither label.”

All eight justices hearing the case agreed that Kidd’s suit against Ashcroft could not go forward; it was the second time in recent years that the court has shielded Ashcroft from lawsuits arising from his role in the fight against terrorism as attorney general from 2001 to 2005. (Justice Elena Kagan sat out the case because she had worked on Ashcroft’s behalf as President Obama’s solicitor general.)

But four of the eight raised questions about the government’s use of the material-witness statute and complained about the treatment of Kidd, who was, in the words of Justice Ruth Bader Ginsburg, “kept in high-security cells lit 24 hours a day, strip-searched and subjected to body-cavity inspections on more than one occasion, and handcuffed and shackled about his wrists, legs and waist.”

Justice Anthony M. Kennedy, who joined Scalia’s opinion in full, nonetheless wrote separately to say that the decision “leaves unresolved whether the government’s use of the Material Witness Statute in this case was lawful.”

Kidd, a onetime University of Idaho football star, was born Lavoni T. Kidd. He converted to Islam in college. He was arrested at Dulles International Airport in 2003 as he was boarding a plane for Saudi Arabia, where he planned to study and where he currently teaches.

The government persuaded a federal judge to issue a warrant for Kidd’s arrest by saying he was necessary to the investigation of Sami Omar al-Hussayen, who was eventually indicted on charges of supporting terrorism. Kidd was never called to testify against Hussayen, who was acquitted of the most serious charges.

Kidd contends that his detention was part of a plan approved by Ashcroft to sweep up Muslim men whom the government suspected, but could not prove, had ties to terrorism.

The U.S. Court of Appeals for the 9th Circuit said Kidd’s lawsuit against Ashcroft could proceed. It said the material-witness statute could not be used as a “pretext” for detaining someone suspected of wrongdoing but whom the government was not willing to charge.

But Scalia, writing for Chief Justice John G. Roberts Jr. and Justices Kennedy, Clarence Thomas and Samuel A. Alito Jr., said the appeals court ruling had no grounding in precedent.

He noted that a neutral federal magistrate had authorized detaining Kidd and that courts need not ascertain the motives behind a “validly obtained warrant.”

At the time of the arrest, Scalia said, “not a single judicial opinion had held that pretext could render an objectively reasonable arrest pursuant to a material-witness warrant unconstitutional.”

That settled the matter as far as whether Ashcroft could be held personally liable, the rest of the court agreed.

But Kidd’s attorney, Lee Gelernt of the American Civil Liberties Union, was encouraged by the additional comments of Kennedy, Ginsburg and Justices Stephen G. Breyer and Sonia Sotomayor.

Ginsburg questioned whether the warrant for Kidd had been validly obtained. She said the information federal agents provided to the magistrate did not point out that Kidd had been cooperating with the government, or that he was less of a flight risk because his parents, wife and children were all U.S. citizens and residents.

Agents said Kidd had booked a $5,000 one-way first-class ticket to Saudi Arabia. Actually, he had bought a round-trip coach-class ticket for $1,700.

Gelernt said the concurring opinions “sent a clear signal” to lower courts to be more demanding when the government seeks to detain someone as a flight risk.

Kidd has reached a settlement with the government for his treatment in detention. Ginsburg noted that the use of falsehoods and misrepresentations could negate any claim of immunity on the part of the federal agents, whom Kidd has sued in a separate case that is pending in Idaho.

The court’s decision Tuesday came in Ashcroft v. al-Kidd .