WASHINGTON — The Supreme Court took sides in a police shooting case Monday, ruling that an Arizona police officer who shot a knife-wielding woman four times was immune from being sued. But Justice Sonia Sotomayor wrote in a dissent that the court’s decision “sends an alarming signal to law enforcement officers 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,” wrote Sotomayor in a dissent joined by Justice Ruth Bader Ginsburg.

The court’s decision comes amid recent demonstrations related to the fatal March 18 shooting by police in Sacramento, California, of Stephon Clark, a 22-year-old unarmed black man. Demonstrations in Sacramento related to the shooting have been taking place almost daily.

READ MORE: What we learned from the independent autopsy into Stephon Clark’s death

The shooting at issue in the Supreme Court case decided Monday happened in May 2010 in Tucson, Arizona. Officers were called to a home following a report that a woman was hacking at a tree with a knife. When they arrived, they saw Amy Hughes come out of the home’s front door holding a kitchen knife.

Officers drew their weapons, and Hughes was told to drop the knife at least twice. She didn’t and Officer Andrew Kisela shot her four times, hitting her in the stomach, hip, arm and knee.

Hughes survived and sued Kisela, arguing he had used excessive force. A trial court initially sided with the officer, ruling that the force he used was reasonable and ending the case. The 9th U.S. Circuit Court of Appeals reversed that decision in 2016, allowing the case to move forward.

In ruling for the officer Monday, the Supreme Court said excessive force is an area of the law where the result depends heavily on the specific facts of each case. Therefore, officers are entitled to immunity unless previous cases clearly tell them a specific use of force is unlawful.

In an unsigned decision, the court noted that Kisela said he shot Hughes because he believed she was a threat to her roommate, who was standing a few feet away. The court also noted that the officer was separated from the two by a chain-link fence and that Hughes failed to acknowledge two commands to drop the knife.

Sotomayor said that rather than letting the case go to a jury, her colleagues decided to “intervene prematurely.”

Sotomayor, in contrast, noted that Hughes was holding the knife down at her side, didn’t raise it in the direction of her roommate or anyone else, didn’t appear agitated and didn’t verbally threaten to harm anyone. She called Kisela’s conduct “unreasonable” and pointed out that two other officers didn’t fire.

Sotomayor said that rather than letting the case go to a jury, her colleagues decided to “intervene prematurely.” She called their decision that Kisela was immune from being sued “unwarranted” and “symptomatic” of a disturbing trend.

She said the court “routinely displays an unflinching willingness” to reverse court decisions for wrongly denying officers immunity but rarely intervenes when courts wrongly grant officers immunity.

An attorney for Hughes, Northwestern University professor David M. Shapiro, called the ruling a “disappointing outcome with troubling implications for police accountability.” Another of her attorneys, Vince Rabago, said Hughes continues to have pain as a result of the shooting.

Associated Press writer Kathleen Ronayne contributed to this report from Sacramento, California.