“It felt like a dangerous time,” she said in an interview this year, referring to her youth. “I can remember my parents’ home getting burglarized and everything getting wiped out while they were at work. And it seems like after that they put bars on the windows and had the iron-gate door. And I really thought everybody in L.A. was doing it because all of the neighbors were doing it.”

It was not until she went away to college at the University of California, Irvine, in suburban Orange County, she said, “that I realized, wait, people don’t even lock their dorm rooms and they have valuable stuff in it. And you could drive down the street and you don’t see bars.”

Ms. Lacey joined the district attorney’s office in 1986, at a time of soaring crime rates. “There was no shortage of homicides, homicide cases available for young lawyers to cut their teeth on,” she said. “It just seemed like a very violent time, gangs were full blown.”

For months, Mr. Gascón has been weighing a challenge to Ms. Lacey, visiting Los Angeles and meeting with local activist groups that have opposed her. In those meetings, Mr. Gascón has touted his record in San Francisco, where he has reduced prison and jail populations and taken measures to reduce racial bias, such as scrubbing demographic information from documents prosecutors use to make decisions about filing charges. He instituted a system to automatically expunge past marijuana convictions, which served as a model for other districts, and established a young-adult court to divert more people away from prison.

This week, a coalition of activists started an advertising campaign in Los Angeles called “Run George Run.” It feature s a billboard alongside a freeway near downtown Los Angeles, where Ms. Lacey works, that associates her with mass incarceration, locking up young people and supporting a “racist death penalty.”

Shaun King, the founder of the influential Real Justice PAC and a prominent critic of mass incarceration, said his organization would support Mr. Gascón financially and with grass-roots organizing, the kind of work it has done in other district attorney races around the country.

“In spite of it being a relatively progressive city it just hasn’t had a progressive legal system, and this is a chance to move it in that direction,” he said. “If there is any system I would classify as a failed system it’s the system there in Los Angeles.”