HONG KONG — Hong Kongers have rarely seen their government react so swiftly to public opinion.

On Thursday, city officials lifted a ban on dining in restaurants — imposed just a day earlier, to fight the spread of the coronavirus — after a public outcry sparked by pictures of workers and older people eating outside in the punishing July heat, on pavements, curbs and the steps of footbridges.

Hong Kong is battling its worst community outbreak since the pandemic began, after initial success in containing the coronavirus. This month, the death toll nearly doubled in a week — as of Friday, it stood at 27 — and infections sharply spiked.

Some new clusters were linked to nursing homes and restaurants, while scores of other cases had no known origin. The government’s initial response included limits on restaurants’ opening hours, with dining in allowed until 6 p.m. but forbidden after that.

But with case numbers staying high, dine-in service was banned altogether on Wednesday — leaving many working-class residents, used to grabbing a quick bite during the lunch hour at one of Hong Kong’s countless inexpensive restaurants, with nowhere to go.

Photos of the results quickly went viral, including one of a 62-year-old cleaner eating in a park during a downpour, huddled under an umbrella. (“What can I do; I can only blame myself for being poor,” a local news outlet, Citizen News, quoted the man as saying.)

Chan Chun-heung, 50, who sells vegetables at a wet market in the Wan Chai District, said she had to eat her Wednesday lunch sitting on the ground.

“I had to cover my food whenever someone walked past me, otherwise the dust would get everywhere,” Ms. Chan said. “And it was so hot.”

Critics accused the government of failing to think about working people who can’t spend their lunch breaks in air-conditioned offices. Stung by the reaction, officials scrambled to open 19 community centers across the city as makeshift shelters where people could go for lunch.

Then, on Thursday, it reversed the policy altogether, announcing that dining in for breakfast and lunch could resume the next day. (Dinner is still limited to takeout or delivery.)

The mini-furor tapped into longstanding perceptions that Hong Kong’s policymakers, many of them well-heeled, are out of touch with how most people live. (Carrie Lam, the city’s unpopular leader, was once mocked for not knowing where to buy toilet paper.)

Daphne Ho, the organizing secretary of the Construction Site Workers General Union, said many construction workers had crowded together in a covered area for lunch on Wednesday. Others ate at dust-filled, poorly ventilated construction sites, and some opted to skip lunch altogether, she said.

“Many people thought, why couldn’t Hong Kongers even have the dignity to eat a meal?” Ms. Ho said. “Why did they have to squat in the streets?”

Ms. Chan, the vegetable seller, was relieved on Thursday to be able to eat at one of the converted shelters near her market. A few other residents ate takeout at sparsely distributed tables, all facing the wall, while a pack of reporters waited outside to interview them.

Before the shelters were opened, a wide variety of venues — including churches, hotels, clinics, hair salons and art studios — had offered to let people eat in their facilities free. Critics of the government were quick to tie that spirit of grass-roots solidarity to the city’s pro-democracy protest movement, which has seen a variety of mutual aid networks spring up.

Health officials have tied Hong Kong’s current surge to incoming travelers who had been exempted from quarantine requirements, including airline crew, sailors and some business executives. (Quarantine rules have since been tightened.)

Ben Cowling, a professor of infectious disease epidemiology at the University of Hong Kong, said that unless crowds were present, eating lunch outdoors was a “low-risk activity, but not very comfortable.”

But the risks of dining in are also limited, he said, “given the measures that had already been put in place in restaurants, including screens between tables, temperature checks and hand sanitizers.”