SAN JOSE (CBS SF/BCN) — The Santa Clara County District Attorney’s office has ruled that an undercover San Jose police officer acted lawfully when he shot and killed Demetrius Stanley in May.

Stanley, 31, died in the shooting shortly before 9:45 p.m. on May 31 in the 1100 block of Tofts Drive where plainclothes officers had gone on a surveillance operation related to a prior criminal case involving him.

READ MORE: Highway 1 Cliff Plunge Victim Identified As Elderly San Francisco Man

Officers were on the stakeout, trying to figure out how they could safely arrest Stanley, who was wanted for an armed robbery.

Stanley came out of his house armed with an unregistered handgun and chased an unarmed undercover officer pretending to be a jogger down the street, according to police.

He then stopped and walked back, passing an unmarked vehicle where a second plainclothes officer was seated.

READ MORE: Grand Jury Indicts 2 Stockton Officers Fired for Beating Black Teen

The officer knew Stanley was armed so the officer did not get out to confront him, but Stanley allegedly opened the driver’s side door and pointed the gun at the officer, prompting the officer to fire his handgun.

“As soon as Stanley opened the car door, Officer Baza was staring down the barrel of a loaded semiautomatic handgun,” Deputy District Attorney Rob Baker wrote in the report. “In that split second, Officer Baza had no other reasonable choice than to shoot Stanley to save his own life.”

The officers involved in the fatal shooting were identified as Hans Jorgenson and Anthony Baza. Both are members of the Police Department’s Covert Response Unit.

The shooting triggered local demonstrations. On June 1st, nearly 100 protesters also took the streets to voice their anger. They blocked off northbound 87 and marched onto Taylor Street and then on to police headquarters.

On June 5th, a group of boisterous protesters marched through the streets of San Jose to the home of Mayor San Liccardo, demanding action in response to Stanley’s death.

Chanting ‘What do we want? Justice now’ and carrying signs calling for the defunding of the San Jose Police Department, the marchers were met by a line of riot-geared officers when they reached the mayor’s neighborhood.

MORE NEWS: FDA Advisers Endorse Pfizer Booster Shots for Elderly, High-Risk Americans

There were no arrests reported.