As in his first campaign, in which he ran against six other candidates, Mr. Krasner, 60, won significant support from Black voters in the northern and western parts of the city. Those neighborhoods have been the most affected by gun violence, and were places where Mr. Vega, 64, had hoped to make inroads.
“Black voters — and not just Black voters — believe that change is necessary and that the direction that Larry Krasner is taking is the right direction,” said State Senator Vincent J. Hughes, who represents several of those neighborhoods. “This is not a close victory. It is an affirmation that we have to go in a different direction in the pursuit of justice.”
Enthusiasm for what used to be a low-turnout race remained high. When all the votes are counted, including mail-in ballots, turnout will almost certainly be higher than it was four years ago, when 155,000 people voted in the Democratic primary.
Mr. Vega, a longtime homicide prosecutor, was among the first employees whom Mr. Krasner fired after taking over the district attorney’s office in 2018. Mr. Vega argued that the leniency of Mr. Krasner’s policies had led to the increase in crime.
Criminologists said there would be no way to prove Mr. Vega’s assertions. David S. Abrams, a professor of law and economics at the University of Pennsylvania who has tracked crime statistics across the country over the past year, said any theory would have to take into account both the rise in homicides and shootings and the overall decline in crime, at least through 2020.
“It’s a mystery,” he said. “There are a ton of theories, almost none of which fit all the facts.”
Mr. Vega received ample support from the police, whose powerful union poured tens of thousands of dollars into his campaign and tarred Mr. Krasner as soft on crime at every opportunity.
Mr. Krasner won office four years ago as part of a new breed of progressive prosecutors. In addition to upholding his campaign pledge not to prosecute low-level crimes, he lowered the number of people in the city’s jail by more than 30 percent.