The New York City mayor’s race began in the throes of a pandemic, in a shuttered city convulsed by a public health catastrophe, economic devastation and widespread protests over police brutality.

Now, with voters heading to the primary polls on Tuesday, New York finds itself in a very different place. As the city roars back to life, its residents are at once buoyed by optimism around reopenings, but also anxious about public safety, affordable housing, jobs — and the very character of the nation’s largest city.

The primary election marks the end of an extraordinary chapter in New York’s history and the start of another, an inflection point that will play a defining role in shaping the post-pandemic future of the city. The leading mayoral candidates have promoted starkly divergent visions for confronting a series of overlapping crises, making this primary, which will almost certainly determine the next mayor, the most significant city election in a generation.

Public polling and interviews with elected officials, voters and party strategists suggest that on the cusp of Tuesday’s election, Eric Adams, the Brooklyn borough president, is the front-runner, fueled by his focus on public safety issues and his ability to connect in working- and middle-class communities of color.

Yet even on the last weekend of the race, the contest to succeed Mayor Bill de Blasio appears fluid and unpredictable, and credible polling remains sparse.

Two other leading candidates, Andrew Yang and Kathryn Garcia, campaigned together on Saturday in Queens and Manhattan, a show of unity that also injected ugly clashes over race into the final hours of the election, as Mr. Adams accused his rivals of coming together “in the last three days” and “saying, ‘We can’t trust a person of color to be the mayor of the City of New York.’”

Mr. Yang, at a later event, noted that he had been “Asian my entire life.” (Mr. Adams later clarified that he meant that Mr. Yang and Ms. Garcia were trying to prevent a Black or Latino candidate from becoming mayor.)

The primary election will ultimately offer a clear sense of Democratic attitudes around confronting crime, a major national issue that has become the most urgent matter in the mayoral primary.

The outcome will also show whether New Yorkers wanted a political outsider eager to shake up City Hall bureaucracy, like Mr. Yang, or a seasoned government veteran like Ms. Garcia to navigate staggering challenges from issues of education to evictions to economic revival.

And it will reveal whether Democrats are in the mood to “reimagine” a far more equitable city through transformational progressive policies, as Maya D. Wiley is promising, or if they are more focused on everyday municipal problems.

In recent polls and last-minute fund-raising, Ms. Garcia, the city’s former sanitation commissioner, and Ms. Wiley, a former counsel to Mr. de Blasio, seem to be gaining late traction, while Mr. Yang, a former presidential candidate, remains a serious contender even amid signs that his momentum may have stalled.

But other factors may muddy the outcome.

For the first time in New York City, the mayoral nominee will be determined by ranked-choice voting, which allows New Yorkers to rank up to five candidates in order of preference. Some New Yorkers remain undecided about how to rank their choices, and whether to rank at all.

And with many New Yorkers accustomed to a primary that usually takes place in September, it is not at all clear what the composition of a post-pandemic June electorate will look like.

For such a high-stakes election, the contest has felt at once endless and rushed. For months, it was a low-key affair, defined by dutiful Zoom forums and a distracted city.

But if there has been one constant in the last month, it has been the centrality of crime and policing to the contest.

“Public safety has clearly emerged as a significant issue,” said Representative Hakeem Jeffries, New York’s highest-ranking House member, when asked to name the defining issue of the mayor’s race. “How to balance that aspiration with fair, respectful policing, I think has been critical throughout the balance of this campaign.”

Six months ago, few would have predicted that public safety would be the top issue of the race, only a year after the“defund the police” movement took hold in the city. Crime rates are far lower than in earlier eras, and residents are confronting a long list of challenges as the city emerges from the pandemic.

But amid a rise this spring in shootings, jarring episodes of violence on the subways, bias attacks against Asian Americans and Jews — and heavy coverage of crime on local television — virtually every public poll shows public safety has become the biggest concern among Democratic voters.

Mr. Adams, Ms. Garcia, Mr. Yang and Raymond J. McGuire, a former Citi executive, vigorously disagree with the “defund the police” movement. But no one has been more vocal about public safety issues than Mr. Adams, a former police captain who has declared safety the “prerequisite” to prosperity.

Mr. Adams, who had a complex career at the Police Department and battled police misconduct as a leader of 100 Blacks in Law Enforcement Who Care, an advocacy group, says that he was once a victim of police brutality himself, and argues that he is well equipped to manage both police reform and spikes in violence.

In recent weeks, however, Mr. Adams has come under growing scrutiny over questions of transparency and ethics tied to taxes and disclosures around real estate holdings. That dynamic may fuel doubts about his candidacy in the final days, as his opponents have sharply questioned his judgment and integrity.

If he wins, it will be in part because of his significant institutional support, as a veteran politician with union backing and relationships with key constituencies — but also because his message connects at a visceral level in some neighborhoods across the city.

“Mr. Adams! You got my vote!” Blanca Soto, who turns 60 on Monday, cried out as she walked by an Adams event in Harlem on Thursday.

“I am rooting for him because he’s not going to take away from the police officers,” said Ms. Soto, a health aide, who called safety her top issue. “I do want to see more police, especially in the subways. We had them there before. I don’t know what happened, but everything was good when that was going on.”

Mr. Stringer, the city comptroller; Shaun Donovan, a former federal housing secretary; Ms. Morales, a former nonprofit executive; and Ms. Wiley have taken a starkly different view on several policing matters. They support varying degrees of cuts to the Police Department’s budget, arguing for investments in communities instead. The department’s operating budget has been about $6 billion. Ms. Wiley, Mr. Stringer and Ms. Morales have also been skeptical of adding more police officers to patrol the subway.

Ms. Wiley argues that the best way to stop violence is often to invest in the social safety net, including in mental health professionals, violence interrupters and in schools.

Understand the N.Y.C. Mayoral Race

Ms. Wiley, who has been endorsed by some of the most prominent left-wing leaders in the country, including Representative Alexandria Ocasio-Cortez of New York and Senator Elizabeth Warren of Massachusetts, is seeking to build a coalition that includes white progressives as well as voters of color across the ideological spectrum.

Rival campaigns have long believed that she has the potential to build perhaps the broadest coalition of voters in the race, but polls suggest that she has not yet done so in a meaningful way.

Mr. Jeffries, who has endorsed Ms. Wiley and campaigned with her, said that she offers change from the status quo, “a fresh face” who is both prepared “and is offering a compelling vision for investing in those communities that have traditionally been left behind.”

Mr. Jeffries has said that he is ranking Mr. Adams second, and that if Mr. Adams were to win, it would be on the strength of Black and Latino communities “who have increasingly felt excluded from the promises of New York City, as it has become increasingly expensive.”

A number of campaigns and political strategists see Latino voters as the crucial, late-breaking swing vote, and the leading candidates all see opportunities with slices of that diverse constituency, with candidates including Mr. Adams and Ms. Wiley airing new Spanish-language ads in recent days — an Adams spot criticizes Ms. Garcia in Spanish — and Mr. Yang spending Thursday in the Bronx, home to the city’s largest Latino population.

Mr. Yang, who would be the city’s first Asian American mayor, is betting that he can reshape the electorate by engaging more young, Asian American and Latino voters as he casts himself as a “change” candidate.

Mr. Yang was a front-runner in the race for months, boosted by his strong name identification and air of celebrity, as well as a hopeful message about New York’s potential and an energetic in-person campaign schedule.

But as New York reopened and crime became a bigger issue in voters’ minds — and as Mr. Yang faced growing scrutiny over gaffes and gaps in his municipal knowledge — he has lost ground.

His tone in the homestretch is a striking departure from the exuberant pitch that defined his early message, as he sharpens his criticism of Mr. Adams and tries to cut into his advantage on public safety issues. Mr. Yang, who has no city government experience, has also sought to use that outsider standing to deliver searing indictments of the political class.

Ms. Garcia has moderate instincts — she was one of the few leading mayoral candidates to favor President Biden as her first choice in the presidential primary — but she is primarily running as a pragmatic technocrat steeped in municipal knowledge.

She has been endorsed by the editorial boards of The New York Times and The New York Daily News, among others, and has generated palpable traction in politically engaged, highly educated corners of the city, like the Upper West Side, even as Mr. Stringer and Mr. Donovan have also vied for the government experience mantle.

“I don’t think New York does that well, as progressive as I am, with a series of progressives who think that we should spend more time dealing with those kinds of issues rather than actual stuff that needs to be done,” said William Pinzler, 74, as he prepared to vote for Ms. Garcia at Lincoln Center. “Kathryn Garcia picked up the garbage.”

But Ms. Garcia, who has struggled to deliver a standout moment during several televised debates, is in many ways still introducing herself, and it is not yet clear whether she can attract the same kind of support citywide.

Asked what lessons national Democrats may take from the results of Tuesday’s contest, Representative Grace Meng, who has endorsed Mr. Yang as her first choice and Ms. Garcia as her second, and appeared with them on Saturday, pointed to questions of both personal characteristics and policy visions.

“How much people prioritize a leader with experience or vision to get us out of the pandemic, but also to address issues like public safety and education — I think that it’ll kind of be a filter through which we see the next round of elections nationally,” she said. “Wherever they may be.”