SAN FRANCISCO — Last year, with pandemic lockdowns in the rearview mirror, Whole Foods Market made a bet on a gritty San Francisco neighborhood. The high-end supermarket chain opened a giant flagship store in a part of the city that is home to both tech companies like Twitter and open-air drug dealing.

But the store was soon confronted head-on with many of the problems plaguing the area. People threatened employees with guns, knives and sticks. They flung food, screamed, fought and tried to defecate on the floor, according to records of 568 emergency calls over 13 months, many depicting scenes of mayhem.

“Male w/machete is back,” the report on one 911 call states. “Another security guard was just assaulted,” another says. A man with a four-inch knife attacked several security guards, then sprayed store employees with foam from a fire extinguisher, according to a third.

In September, a 30-year-old man died in the bathroom from an overdose of fentanyl, a highly potent opioid, and methamphetamine.

When Whole Foods announced in mid-April that it was closing the store, citing the safety of its employees, many in San Francisco saw it as a representation of some of the city’s most intractable problems: property crimes like shoplifting and car break-ins, an entrenched network of dealers selling fentanyl and other illicit drugs and people suffering from untreated mental illness wandering the streets.

The closure also seemed to be the latest indicator of San Francisco’s faltering economic prospects, providing more grist for an ongoing debate over where the city is headed after tying its fate to the tech industry. The Whole Foods was supposed to cater to tech workers and other professionals, part of a long-term redevelopment plan downtown. But the store fell victim to a grinding decline in the city’s center that began with the pandemic and could continue for years as companies vacate offices because of remote work.

In a city famous for its boom-and-bust cycles, San Francisco’s continued slump has left residents in a sour mood, angry at city leaders and waiting for the sparks of revitalization. Now, largely because the tech industry has so wholeheartedly embraced work-from-home, activity in San Francisco’s downtown remains at roughly a third of prepandemic levels — lower than in about 50 other major cities, according to one new study that used cellphone data as a measure.

“This is going to be a very slow recovery,” Effi Shoua said this month from behind his desk at the downtown fine art gallery he owns in Union Square. The area is a prime spot for tourists, who have been steadily returning to the city, a bright spot and a contrast to the 26 percent vacancy rate of downtown offices.

Many merchants are worried about a domino effect of commercial failures if office workers are permanently absent for about half of the week, while people using drugs, going through mental crises or living on the street remain more visible than ever.

The impact on the city’s budget is significant, too: Office-based industries account for nearly three quarters of the city’s gross domestic product. After years of surpluses, the government now forecasts a $780 million deficit in the upcoming two fiscal years — roughly a 6 percent cut in its general fund, according to the mayor’s office.

City officials say they are searching for ways to diversify the economy and to reduce homelessness and drug dealing. They realize that some of the largest local employers, Big Tech companies, will not be towing San Francisco from its economic shoals. Twitter, Google, Facebook and Salesforce, all of which have offices in the city, have laid off thousands of workers.

San Francisco leaders point out that the city has rebounded again and again, including after the near-collapse of the tech industry in 2000 and the national recession about eight years later.

“We’ve been counted out before, and there have been others who have tried to imply because things aren’t happening as fast or the way that they think it should happen, that it’s over,” London Breed, the city’s mayor, said in an interview.

In the famously liberal city, where Republicans make up just 7 percent of the electorate, moderate Democrats like Mayor Breed are calling for aggressive steps to address public safety concerns while progressive voices decry law-and-order strategies as kneejerk responses that trample on the vulnerable.

City leaders face some limitations. A federal judge in April determined that San Francisco cannot clear homeless people from public spaces because it has not done enough to provide shelter. Mayor Breed is backing bills in the State Legislature that would make it easier to force mentally ill people into treatment. The mayor has also proposed addressing homelessness by building more: slashing the permitting process for construction with the goal of building 83,000 additional homes and apartments — a 20 percent increase from the city’s current total housing stock — in eight years.

Even though the downtown is plastered with “for lease” signs, the city’s unemployment rate is under 3 percent and the mayor and other officials say the engineering talent pool remains the city’s top asset. And there is much more to San Francisco than its downtown. It has always been a constellation of very different neighborhoods, some of which have very few of the social ills that afflict the area near the closed Whole Foods.

Officials add that the downtown may ultimately emerge more resilient if it attracts industries like life sciences and bio-tech whose employees still need work space. There is growth in the tech industry, too: The development of artificial intelligence, which promises to transform the way that people live and work, is centered in San Francisco.

Garry Tan, the president of Y Combinator, a prominent venture-capital company, says he sees signs of renewal in San Francisco. “It’s the gold rush over and over and over again,” he said.

Mr. Tan is part of a generation of tech workers who are more assertive in their demands on city officials, unafraid to take sides in the city’s internecine politics and funding organizations that press for more emphasis on public safety.

“Now the narrative out there for some of the founders in our community is, I’m not sure if I feel safe here. I’m not sure if I want to stay here. The quality of life issues are the question. Can I raise a family here?”

In early April, some tech leaders seized upon the recent fatal stabbing downtown of Bob Lee, a prominent industry executive, as an alarming sign that the downtown was unsafe. But an acquaintance was later accused, and San Francisco’s murder rate is quite low compared with other major cities. Overall, police statistics show fewer property and violent crimes in 2022 than in 2018, before the pandemic began.

Still, Bill Scott, the city’s police chief, says many residents complain that they feel less safe, and the open-air drug use, much of it tied to fentanyl, is a major contributor.

Matt Dorsey, a member of the board of supervisors who lives steps away from the shuttered Whole Foods, said recent elections had signaled a shift in voter priorities. He pointed to last year’s recall of the city’s progressive district attorney, Chesa Boudin, who was replaced by a prosecutor who vowed to be tougher on crime.

“San Francisco is in the midst of a voter revolt on public safety,” Mr. Dorsey said. In a poll conducted by the San Francisco Chronicle in September, nearly two-thirds of respondents said life in the city was worse off than when they moved here.

The new district attorney, Brooke Jenkins, has begun prosecuting more drug crimes than Mr. Boudin, but the city experienced a 40 percent jump in fatal overdoses in the first quarter compared with the same period last year.  Citing that statistic, Gov. Gavin Newsom on Friday authorized an antidrug task force in San Francisco that will include members of the California National Guard and California Highway Patrol.

The mayor and the police chief have vowed to hire hundreds of additional officers, which would expand the force by more than one-fourth, a difficult proposition when law enforcement agencies nationwide are facing shortages.

Not everyone is on board with that.

Dean Preston, a member of the board of supervisors who was re-elected in 2020 on a Democratic Socialist platform, is against increasing police staffing and believes calls for greater public security are overstated.

“There’s been a massive propaganda effort to change public opinion around policing and public safety,” he said.

Mr. Preston uses his district as an example of how uneven the pandemic recovery has been. Some areas like Japantown and Haight Ashbury are thriving, he said. Others like the Tenderloin, which is adjacent to the shuttered Whole Foods, are beset by drug dealing and homelessness.

One of the next big tests for downtown might be this summer’s expected opening of an Ikea store not far from the Whole Foods site.

Police described theft as rampant at Whole Foods, with thieves walking out with armfuls of alcohol, at least at the start. After 250 shopping hand baskets were stolen, the company restocked with 50 more. Those went missing, too.

During the store’s 13 months in operation, at least 14 people were arrested, including on charges of grand theft and battery, according to official reports. Chief Scott said that plainclothes officers were sent there and security improved over time, but seemingly not enough for the company.

On a recent chilly night across from the shuttered store, Joseph Peterson, a former construction worker who lost both of his legs to diabetes and is homeless, rolled down the sidewalk in his wheelchair. Mr. Peterson could see the 2,000-unit Trinity apartments, the high-end complex that Whole Foods had hoped would be its customer base. Across the intersection, security guards stood sentry in front of the Orpheum Theater, where “Pretty Woman: The Musical” was playing. A few dozen steps away, dealers peddled fentanyl and crystal meth.

Mr. Peterson said he understood why Whole Foods had closed the store.

“People kept stealing from it,” he said. He, too, had taken macaroni and cheese and chicken from the hot food bar a number of times, he said. But he made a distinction. Other people stole from the store because they wanted to resell what they took.

“I just stole to eat,” he said.

Alain Delaquérière, Susan C. Beachy and Kitty Bennett contributed research.