CASTAIC, Calif. — When Kamala D. Harris, a Democrat, was the newly elected district attorney of San Francisco in 2004, she walked into a firestorm after deciding not to pursue the death penalty for a man accused in the killing of a police officer — drawing attacks from law enforcement leaders and even Senator Dianne Feinstein, one of the most respected Democrats in the state.

Six years later, when Ms. Harris ran for state attorney general, national Republicans poured more than $1 million into the race, trying to defeat her with charged advertisements invoking the death penalty case. Ms. Harris barely defeated her Republican opponent, the district attorney of Los Angeles.

But now, at age 50 and after winning a second term, Ms. Harris has suddenly established herself as the dominant candidate in the race to replace Senator Barbara Boxer, a Democrat who announced in January that she would retire next year. With a speed and efficiency that startled many in her party, Ms. Harris has appeared, at least for now, to dispatch what most people had expected would be a sprawling generational battle with powerful ethnic overtones, given that Latinos now make up nearly 40 percent of California’s population.

She herself would be a pioneering figure, if elected — simultaneously the first black and the first South Asian senator from California.