A sharply divided U.S. Supreme Court ruled Monday that an Arizona police officer who shot a knife-carrying woman four times outside her home could not be sued on claims that he used excessive force, marking the latest in a series of high court decisions shielding officers from such lawsuits.

In an unsigned opinion, the court found that the officer was entitled to qualified immunity, a legal doctrine that says police are immune from excessive force lawsuits as long as they don’t violate “clearly established” rights that a “reasonable person would have known.”

Justice Sonia Sotomayor wrote in a dissent, joined by Justice Ruth Bader Ginsburg, that the ruling “sends an alarming signal to law enforcement and the public.”

“It tells officers that they can shoot first and think later, and it tells the public that palpably unreasonable conduct will go unpunished,” Sotomayor wrote.

The decision came as days-long protests over the fatal shooting of an unarmed black man by Sacramento police continued in California’s capital city, with demonstrators demanding accountability for the officers who killed 22-year-old Stephon Clark outside his grandmother’s house last month. Outcry over the 2016 fatal police shooting of Alton Sterling in Baton Rouge has also resurfaced in recent days after prosecutors declined to charge the officer.

The case decided by the Supreme Court stemmed from a May 2010 shooting in Tuscon, Ariz. Three officers from the University of Arizona were dispatched to a house near campus after receiving a “check welfare” call about a woman hacking at a tree with a kitchen knife. When they arrived, the woman, Amy Hughes, emerged from the house with a large blade at her side. Her roommate, Sharon Chadwick, was standing several feet away from her.

Hughes “appeared calm” but ignored officers’ commands to drop the knife, according to the court’s ruling. Worried that Hughes was threatening Chadwick, one officer, Andrew Kisela, shot her four times through a chain-link fence. Hughes was treated at the hospital and survived her injuries. Chadwick stated later that Hughes had a history of mental illness and that she never felt endangered by Hughes, according to the ruling. No crime was reported, and Hughes was not charged with any offense.

Hughes sued Kisela, alleging violations of her Fourth Amendment rights, which protect against excessive force. The case ping-ponged through the court system for several years and was eventually allowed to move forward under a ruling by the U.S. Court of Appeals for the 9th Circuit.

But the Supreme Court reversed the decision, finding that the facts of the case favored the officer, whose conduct did not “violate clearly established statutory or constitutional rights of which a reasonable person would have known.”

Citing precedent, the court said that the question of whether an officer used excessive force hinges on the specifics of each case, including whether the suspect posed an immediate threat, and that the reasonableness of a use of force must be judged from the officer’s perspective. Officers were entitled to qualified immunity as long as no similar precedent existed showing a specific use of force was unlawful.

The court noted that the officer believed Hughes was a threat to her roommate and had “mere seconds to assess the potential danger.”

“This is far from an obvious case in which any competent officer would have known that shooting Hughes to protect Chadwick would violate the Fourth Amendment,” read the majority opinion.

The officer was represented in the case by the Arizona attorney general’s office, which argued that the officer acted reasonably and that qualified immunity was warranted. An attorney for Hughes told the Associated Press that the ruling was a “disappointing outcome with troubling implications for police accountability.”

In her dissent, Sotomayor noted that Kisela was the only officer on the scene who used deadly force, and that he did so without warning that he would open fire. Hughes was not suspected of a crime, she said, nor did she raise the knife in anyone’s direction.

“If this account of Kisela’s conduct sounds unreasonable, that is because it was,” Sotomayor wrote. “And yet, the Court today insulates that conduct from liability under the doctrine of qualified immunity, holding that Kisela violated no ‘clearly established’ law.”

If the case were tried in open court, she wrote, a jury could have determined whether the officer violated Hughes’s constitutional rights “by needlessly resorting to lethal force.”

“In holding otherwise,” she wrote, “the Court misapprehends the facts and misapplies the law, effectively treating qualified immunity as an absolute shield.”

The court has ruled in favor of officers in a string of excessive force cases in recent years, often reversing lower courts that deny officers qualified immunity and making it harder for victims to pursue jury trials. In one such case, the court in 2015 granted qualified immunity to a Texas state trooper who fired into a suspect’s car during a high-speed chase, despite being ordered not to do so by his superiors. Sotomayor, the lone dissenter, criticized what she called a “shoot first, think later” mentality.

Some police officials say the court’s broad application of qualified immunity has protected officers against frivolous lawsuits. Recent rulings “demonstrate the Court’s continued determination to give police officers the benefit of doubt when reviewing their split-second life changing decisions from the entirely safe contours of judicial chambers,” former FBI chief division counsel Mike Callahan wrote in PoliceOne.

But the libertarian Cato Institute, which filed an amicus brief in the case, said the court’s support for qualified immunity helped “create a policy of near-zero accountability for law enforcement.”

The organization’s vice president, Clark Neily, told the Los Angeles Times on Monday: “Today’s ruling gives yet another green light to officers who use deadly force as a tool of first resort instead of last.”

More from Morning Mix: