The election in Chicago is the latest race in a large, liberal American city in which crime has been a primary issue. In New York City, Mayor Eric Adams, a Democrat and former police captain, defeated progressive candidates in his party’s 2021 mayoral primary by calling for a crackdown on crime. And in Los Angeles last year, Karen Bass, a liberal congresswoman, was elected mayor in a race in which her more conservative opponent, Rick Caruso, a billionaire real estate developer, ran on a law-and-order message.

Mr. Vallas, 69, made public safety the focus of his campaign, calling for tougher prosecutions of minor offenses and a rapid expansion of the Chicago Police Department, which is operating under a consent decree in federal court and without a permanent superintendent. That platform helped Mr. Vallas finish in first place in the first round of the election in February, though well short of the outright majority he would have needed to clinch the job without a runoff.

In a heavily Democratic city, Mr. Vallas has faced criticism for past comments that he considered himself to be more of a Republican than a Democrat, and for an endorsement from the local chapter of the Fraternal Order of Police, whose leaders frequently use brash rhetoric and support Republican politicians. Still, his description of Chicago as a city in crisis and his pledge to get crime under control resonated with many voters.

“I’m tired of looking out my window and watching drive-by shootings,” said Sherri Ortiz, a West Side resident who said this week that she was leaning toward Mr. Vallas, who she believed was more likely to fix things quickly.

Mr. Johnson, 47, qualified for the runoff by defeating several better-known candidates competing for the same liberal voters. A former social studies teacher, Mr. Johnson has spent the last dozen years as an employee of the Chicago Teachers Union, a powerful but polarizing political force that contributed heavily to his campaign. In recent weeks, he has described a public safety vision that goes beyond law enforcement, but has tried to distance himself from past support for defunding the police.