ALBUQUERQUE, N.M. — The hung jury in the murder trial against two former Albuquerque police officers underscores the difficulty prosecutors often face in landing convictions against law enforcement in deadly shootings, as they contend with concerns over the handling of evidence and cooperation of department witnesses.

The final hurdle for prosecutors often comes at trial as they try to win over jurors who experts say typically are reluctant to second guess the split-second decisions of police. In the Albuquerque case, Detective Keith Sandy and Officer Dominique Perez — both no longer with the Police Department — testified that they fatally shot a homeless camper armed with two knives to protect the life of another officer who came within 10 feet of the suspect during a standoff.

Jurors deadlocked Tuesday in weighing second-degree murder charges against Sandy and Perez, leading a judge to declare a mistrial in a case that has divided New Mexico’s largest city for more than two years and raised questions about how best to handle investigations into shootings by police. The nearly three-week trial played out amid a national debate about officers’ use of deadly force, including how to interact with mentally ill suspects.

Activists protested the verdict Wednesday outside the Albuquerque courthouse where the case was tried.

The protesters made their way up Central Avenue downtown and toward the University of New Mexico campus before the crowd appeared to disperse around 8 p.m.

Some protesters wore masks and others yelled profanities at the police. Officers in riot gear blocked off large swaths of downtown while helicopters circled overhead.

“Police departments probably shouldn’t investigate their own police officers,” said Randi McGinn, the special prosecutor who was assigned the case after a judge ruled the district attorney had a conflict of interest with police. “That’s the most important thing, and — by the way — the only way the public will have confidence in the system.”

Nationwide, 77 officers have been charged with murder or manslaughter in on-duty shooting deaths since 2005, while in 2015 — the year Sandy and Perez were arraigned — 18 were charged, according to data from Philip Stinson, a criminal justice professor at Bowling Green State University in Ohio.

Twenty-six of the 77 officers charged were convicted, 13 of them by a jury and 13 by guilty pleas.

“The jurors seem to understand that police work is dangerous, so it really, really has to be a case over the top where you can second guess an officer,” Stinson said. “With law enforcement, they start from the position it’s justified and work from there.”

In the Albuquerque shooting, police video from Perez’s helmet camera shows Boyd, who was diagnosed with paranoid schizophrenia, gathering his belongings and telling police he’ll walk down a hillside with them when Sandy deploys a flash-bang grenade. Seconds later, a K-9 officer releases his police service dog on Boyd, and then chases after the animal — a fateful move that appeared to prompt the camper to pull two knives and defense attorneys say led Perez and Sandy to shoot.

Seventeen other officers had responded to the standoff with Boyd, which started with a resident complaint about his campsite several hundred feet behind some homes. The encounter escalated when the camper pulled two small knives and shouted death threats down at police he stood below him on a rock slope, authorities said.

But McGinn, the special prosecutor, countered during the more than two-week trial that it was police who were responsible for agitating Boyd and intensifying the standoff with a show of force that included rifles, tactical gear, flash grenades, stun guns and K-9 units. She also faulted Sandy, who was a detective in a now-dismantled unit that targeted violent career criminals, for taking a central role in decisions that she says led to Boyd’s death, including disrupting negotiations between him and a crisis intervention officer.

He and his attorneys denied the accusations.

“These officers followed their training to a ‘T’,” said defense attorney Sam Bregman, who represented Sandy. “When cops follow their training they shouldn’t be prosecuted for it.”

Defense attorneys argued the case was not about how police handled the encounter but whether Sandy and Perez were justified in shooting Boyd, saying they were at the mercy of decisions made by higher-ranking officers and a system that had made them into default mental health professionals.

The defense also portrayed Boyd as a dangerous man with a history of violence that included prior assaults on officers. Sandy and Perez said police exhausted all options in negotiating with Boyd and had no other choice but to shoot once he made what they said was a menacing move toward the K-9 handler. Sandy shot Boyd twice in the arms, and Perez shot him in the back.

For the prosecution, one of the early hurdles stemmed from police’s lack of certainty over which of the officer’s bullets hit Boyd in the back and which struck him in the arms.

It also came out during a prelimary hearing held a year ago to determine whether there was enough evidence to charge the officers that police hadn’t reconstructed the scene of the shooting — typically a standard step in a homicide case — so an outside expert was hired by the prosecution to construct an analysis of the scene.

During the trial, McGinn highlighted another challenge in a court filing, saying the special circumstances of the case resulted in her relying on the testimony from the defendants’ fellow officers to try to prove the shooting was unjustified. She said that some of them couldn’t help but have “a bias in favor of the defendants.”

“We were hoping to create a template for these cases moving forward,” McGinn said. “They need somebody outside investigating, whether they have an attorney general investigate them all, or put together a team of outside law enforcement.”

Nine jurors wanted to acquit Sandy and Perez in the shooting, and three were holding out for a guilty verdict. The mistrial means a decision on whether to retry the case will be in the hands of Raul Torrez, a Democrat and former federal prosecutor who is running unopposed for the district attorney position in Albuquerque.

He said he would not make a decision on how to proceed until after a detailed review of evidence that would come after he takes office.

“This is an extremely important case for our community and we must not rush a decision about how best to proceed,” Torrez said.