SAN FRANCISCO—In Kamala Harris ’s rise from California prosecutor to the second highest office in the U.S., she has maneuvered between embracing progressive ideals and trying not to alienate law enforcement. The result is a record that has drawn mixed reviews from both sides.

Early on, as San Francisco’s district attorney, she launched a jail diversion program for drug offenders. And later, as California attorney general, she implemented a first-of-its-kind program requiring police officers to undergo implicit bias training.

But progressives criticized her for fighting the release of prisoners whose supporters claimed they were wrongfully convicted and for going to court to defend a death penalty she had long opposed. Meanwhile, police groups praised her for those stands.

Wearing the two hats—reform-minded progressive and tough prosecutor—has compelled Harris to perform a balancing act that has continued in Washington.

“I think her political ambitions and own views led her to these centrist positions,” said Paul Butler, a Georgetown law professor and former federal prosecutor.

The expected Democratic nominee has staked her campaign on her unique ability to “prosecute the case” against Trump, the Republican nominee.

“I took on perpetrators of all kinds—predators who abused women, fraudsters who ripped off consumers, cheaters who broke the rules for their own gain,” Harris said at a campaign rally in Wisconsin Tuesday. “So hear me when I say, I know Donald Trump ’s type.”

Meanwhile, Trump is attacking Harris, accusing her of being soft on crime, blaming her for allowing a wave of migrants into the U.S. and criticizing her record as a prosecutor. The Republican National Committee released a video this week that accused her, among other things, of allowing “illegal-immigrant drug dealers” to enter job training when she was San Francisco district attorney.

The job training was part of a new program for nonviolent offenders, which resulted in lower recidivism rates and won praise from the Justice Department, a Harris aide said.

A campaign spokesman described Harris as a “pragmatic prosecutor.”

Harris identified herself as a “progressive prosecutor” during her 2020 bid for the presidency, but former colleagues describe her as more moderate on crime reform than the group of district attorneys who swept into office under the progressive moniker in recent years, with bold promises of reducing incarceration.

“I believe she knows how important the role of law enforcement is in this country, but also how important it is that role be performed equitably,” said Paul Henderson, a fellow Black prosecutor who served as her chief of administration in San Francisco.

Rocky start

Harris launched her political career in 2003 by defeating incumbent San Francisco District Attorney Terence Hallinan, a liberal icon known for his support of medical marijuana and decriminalizing prostitution. A little-known prosecutor at the time, Harris ran to the right of Hallinan, hammering him for a low conviction rate and for being soft on crime.

Harris got off to a rocky start as DA in 2004 when police officer Isaac Espinoza was shot to death on duty and she declined to seek the death penalty against his killer. The decision enraged the city’s police force. She drew more flak when she announced the decision without first informing Espinoza’s widow or explaining it to her.

“California Attorney General Harris never made amends for that slight; neither did U.S. Sen. Harris nor Vice President Harris,” Tracy McCray, president of the San Francisco Police Officers Association, said in a statement.

The backlash stung the young politician. “I think it hurt her and bothered her because it was a false narrative that she didn’t support law enforcement,” Henderson said.

Harris secured a penalty of life without possibility of parole for the killer, a sentence that won her praise from the police union, said a Harris aide, who also noted a local poll at the time showed most San Francisco residents also opposed the death penalty.

Harris sought a stronger bond with police by siding with them on policy matters, local law-enforcement officials said.

Harris didn’t adopt a policy popular among progressive criminal-justice reformers to disclose past misconduct by law enforcement to help ensure defendants received a fair trial, despite her aides recommending such a policy in 2005, The Wall Street Journal has reported .

The decision ended up backfiring five years later, when her office’s lack of what is known as a “Brady policy” was central in a scandal in which around 1,000 criminal cases were dismissed and a judge criticized Harris for violating defendants’ rights.

Her office eventually did implement a Brady policy, a Harris aide said.

“It took too long to implement, but I am proud we implemented a Brady policy in the DA’s office that was later called ‘a model for other jurisdictions’” by the California Supreme Court, Harris said in a previous statement to the Journal.

Harris won her race for attorney general in 2010 by less than 1 percentage point—while Democrats won most other statewide offices in California by double digits—in part because law-enforcement groups, still bitter over her decision on the death penalty, didn’t back her.

Olive branches

Once elected attorney general, she built strong ties with law enforcement leaders by seeking their counsel on pressing political issues, said Mike Durant, who headed the state’s largest police union at the time.

“We had that relationship based on her ability to reach that olive branch that she knew probably wasn’t going to be in the liberal, if you will, best interest,” said Durant. “But she wanted to make sure that law enforcement had a seat at the table.”

After nationwide protests against police brutality in 2014, she pushed to disclose data about officers’ use of force. Before doing so, she consulted with police union officials, who suggested she also include in that data the number of officers injured or killed on duty, which she did, Durant said.

She drew criticism as attorney general from progressives for not doing more—such as seeking DNA testing—to help free inmates whose cases had drawn public attention for possible wrongful conviction.

She also was criticized for going to court to uphold a death penalty case. Harris did so, despite her personal opposition, because she had promised voters she would adhere to existing laws, an aide for Harris said.

National stage

Harris easily won re-election as state attorney general in 2014 and her Senate seat in 2016 with support from both law enforcement and liberal groups.

When she ran for the Democratic nomination for president, she wrestled with how to explain her work as a prosecutor. Her alignment with the “progressive prosecutor” movement that was popular with Democrats at the time frustrated some who were familiar with her record.

“Time after time, when progressives urged her to embrace criminal-justice reforms as a district attorney and then the state’s attorney general, Ms. Harris opposed them or stayed silent,” wrote Lara Bazelon, a law professor at the University of San Francisco, in a 2019 New York Times op-ed.

Bazelon, who didn’t respond to requests for comment, posted on X this week that she supports Harris for president, adding that the column was written “a lifetime ago.”

During a debate among the 2020 Democratic presidential candidates, challenger Tulsi Gabbard assailed the then-California senator, charging that as attorney general “she kept people in prison beyond their sentences to use them as cheap labor for the state of California.”

Harris responded at the debate that she was proud of the work she did as attorney general of California, “of being in the position to use the power that I had to reform a system that is badly in need of reform.”

In 2021, as vice president, Harris was a chief backer of legislation that would have addressed racial profiling and the use of deadly force in the aftermath of the killing of George Floyd by a Minneapolis police officer. Although the bill never made it past the Democratic-controlled House, Harris won points on the left for trying.

Political observers say none of the criticisms over the years really hurt her much with voters, as evidenced by her meteoric rise. “It would be easy to critique her from the left or right in a way that would thwart her,” said Georgetown’s Butler, “but that hasn’t happened.”

Write to Jim Carlton at Jim.Carlton@wsj.com and Zusha Elinson at zusha.elinson@wsj.com