SAN FRANCISCO — Kamala Harris was three months into her tenure as San Francisco district attorney in 2004 when a gang member killed a police officer with a hail of bullets from an AK-47. Her announcement within three days of the murder that she would not seek the death penalty set off protests from her fellow Democrats as well as from police.

Sen. Dianne Feinstein stood in front of thousands of mourners at the officer’s funeral at St. Mary’s Cathedral and urged her to change her mind; Jerry Brown, the once and future governor, was among those standing in ovation. The state attorney general threatened to take over the case, and Sen. Barbara Boxer asked the Justice Department to prosecute it.

Harris, the first person of color elected as this city’s district attorney, declared her decision a matter of principle: The death penalty, she believed, discriminated against poor and black people and would not deter more killing.

But death penalty opponents wondered a decade later where that principle had gone when as California’s attorney general Harris appealed a judge’s decision declaring the state’s death penalty law unconstitutional. She said it was a matter of upholding the law; her critics asked whether she would have similarly defended segregation and statutes against interracial marriage.

Now Harris is running for president as a “progressive prosecutor.” She says she sees no contradiction in the term, arguing that a tough prosecutor can also be a force for reforming the criminal-justice system. But already, she is facing a chorus of skepticism, especially from the left. The death penalty episode shows the tricky crosscurrents that she has had to weather — and that are likely to intensify as she tries to square that circle.

In a dozen years as the top law enforcement official of the city and then the state, Harris was as much politician as prosecutor, appearing to try to be all things to all constituencies.

She developed a reputation for caution, protecting the status quo and shrinking from decisions on contentious issues.

Years before ending mass incarceration became a bipartisan cause, she started programs to steer low-level drug offenders away from prison and into school and jobs. At the same time, she touted her success in increasing conviction rates, and as attorney general remained largely on the sidelines as California scrambled to meet a federal court order to reduce its swollen prison populations. She also repeatedly sided with prosecutors accused of misconduct, challenging judges who ruled against them.

And while she summoned righteous anger toward the bank fraud that helped set off the Great Recession, holding out for more money for California homeowners in the National Mortgage Settlement, she said little when the governor diverted some to fill budget holes.

“She played it very careful,” said Laurie Levenson, a professor at Loyola Law School in Los Angeles who served on an independent panel that investigated one of the cases of prosecutorial misconduct while Harris was attorney general.

She has also had to navigate the shifting politics of crime and race — and the expectations they bring with them.

Harris began her career at a time when many African-American law enforcement officials were joining, even amplifying, law-and-order calls for stricter prosecution, to stop the drugs and violence victimizing their communities. When she became attorney general in 2011, crime was falling and the debate was evolving. Now, in the era of Black Lives Matter, many in the black community argue that the biggest law-enforcement problem is law enforcement itself, and her record is being assessed against calls for a wholesale reimagination of the criminal justice system.

At the other end of the political spectrum, President Donald Trump has sought to frame the immigration debate around fear of rising crime, teeing it up as a campaign issue for 2020.

Harris scorns what she calls false choices, and says her critics are imposing them on her record. Those who have worked for her call her disciplined, a characterization she prefers to “cautious.” She describes her thinking — about criminal justice, but also about the other issues animating her presidential candidacy, like health care and economic inequality — as scientific. “It’s a hypothesis; this is how we can do things better,” she said in a recent interview. “You have to inform it with: Where’s the empirical evidence? Where is the data? Where is the detail?”

Almost immediately, Harris’ decision on the death penalty in the officer’s killing inflamed tensions with police. But it was pragmatic as well as principled: She knew that San Francisco jurors rarely if ever returned death sentences. And despite the protests, polling showed that the public supported her.

Some contend that the episode spooked her, that she spent the rest of her tenure trying to make amends with police. Harris scoffs at the idea, pointing to her diversion program that allowed young low-level offenders to avoid incarceration if they enrolled in school full time and kept a job. “You think law enforcement was supportive of that?” she said.

Arguing that students who skip school are the ones who end up in the criminal justice system, Harris also started an anti-truancy program. She described it as carrot-and-stick: It threatened prosecution for parents whose children were chronically absent, but also helped them with health care problems and other hurdles to getting their children to school.

Critics, though, said it was more stick than carrot, and failed to grapple with the depths of the social problems parents were struggling against.

Either way, the program reflected Harris’ approach to her job.

“Fierce,” said Lateefah Simon, a onetime teenage shoplifter who became executive director of a center that helps lift young women out of lives of crime. Harris recruited her to work in the district attorney’s office, instructed her to lose the Pumas and track pants, bought her a suit and told her she needed to understand the penal code.

As attorney general, Harris defended prosecutors by appealing judges’ rulings — dropping one appeal, during her Senate campaign, only after a video of judges criticizing her office went viral.

In a case in Orange County, a public defender had discovered that the district attorney’s office was strategically placing jailhouse informants, offering them leniency if they could coax confessions from fellow inmates. A judge found that the district attorney’s office had lied to him about the use of informants and withheld potentially favorable evidence from defense lawyers.

When the judge disqualified the entire office from a death penalty case, Harris appealed, accusing the judge of abusing his discretion. While she opened an inquiry into the case at hand, she rejected repeated calls for a broad investigation of the prosecutor’s office.

In the recent interview, Harris said her decision reflected her experience when others had tried to disqualify her from the San Francisco death penalty case. It was up to voters, not the attorney general, she said, to remove elected prosecutors. “I knew misconduct had occurred, clearly it had,” she said. “And it was being handled at the local level.”

Frustrated by her refusal to investigate, Erwin Chemerinsky, then the law school dean at the University of California, Irvine, joined with a former attorney general to ask the Justice Department to examine what they believed was a pattern of civil rights violations in the prosecutor’s office. Their letter was signed by 25 prominent law professors, prosecutors and defense lawyers.

“Twice Kamala Harris called on my cell and said she was on top of it and looking into it,” he said. “To my knowledge, the California AG never did anything with regard to the scandal.”

Chemerinsky emphasized that he admired Harris’ work as a senator. But, he said, her office’s decisions on Orange County were “outrageous.”

“Their reaction ranged from silence to criticizing the judge who found the misconduct,” he said. “Never did they attempt to be a force for reform.”

Her decision to fight the ruling that had struck down California’s capital punishment law in 2015 created similar disappointment among those who had applauded her refusal to call for the death penalty in San Francisco.

“This was not a situation where they were compelled to respond,” said Hadar Aviram, a law professor at Hastings who started a petition against appealing. “They could have done nothing.”

The public, however, had three years earlier rejected a ballot initiative that would have abolished the death penalty in California.

In the interview, Harris said that as attorney general she had to represent her client, the governor, who supported the death penalty appeal. Even so, she had cited her discretion in deciding which cases to pursue when she declined requests to defend Proposition 8, a successful ballot initiative defining marriage as between a man and a woman, in federal courts.

Once again, she said, her critics were framing a false choice: She could defend the death penalty for a client and still be opposed to it personally.

Just as a prosecutor can be tough but also progressive.

“One human being kills another human being, a woman is raped, a child is molested — are we really saying there should be no consequence and accountability?” she said. “I believe it is consistent with knowing that there is bias in the system, knowing that there are deep flaws in the system, knowing that there has to be reform of the system.”

She added: “Are we really saying that you’re either that, or you believe that there should be serious consequences for people who commit serious crimes? I am both.”

This article originally appeared in The New York Times.