SINGAPORE—After four straight days with no Covid-19 deaths and with new cases at their lowest levels since early March, Shanghai is preparing to end more than two months of lockdowns.

The easing of restrictions takes effect Wednesday, but already Tuesday evening social-media posts showed residents swarming the streets, chanting and dancing and posting images of themselves eating out at local restaurants.

The majority of the 25 million residents of China’s financial capital can leave their homes and return to work starting Wednesday, the Shanghai government said. Aside from those in high-risk areas, all businesses can reopen, buses and trains will resume normal operations, and restrictions on private vehicles will be lifted. Shopping malls and other commercial centers can run at 75% of capacity.

Shanghai on Tuesday recorded 29 new locally transmitted Covid-19 infections from the day before, after averaging almost 18,000 a day in April, allowing authorities to further ease some measures. To move freely around the city, residents will now only need a negative PCR test within 72 hours, from 48 hours previously.

Shang Bin, who lives in the city’s Pudong district, found his way to food stands in his neighborhood for late-night snacks he had missed dearly. After gobbling down grilled cold noodles, a northern China delicacy, he devoured some fried chicken, a rare commodity during the lockdown.

“It feels like I’ve finished serving my prison sentence,” he said, adding he was relieved not to have to wake up anymore at 5 a.m., hoping to secure a grocery-delivery slot.

Mr. Shang said about half the diners in his neighborhood were open Tuesday night, quickly filling up with happy customers. “People were screaming in the street,” Mr. Shang said.

But not everyone was in a celebratory spirit.

“I lost two months in my life that I can never get back,” said Euphe Tang, a resident of the city’s Jing’an district.

Ms. Tang said that group-buying of food and supplies had bonded her with her neighbors, but added “the close connections I built with neighbors probably will fade with the end of the emergency.”

The hashtag “Shanghai Is Back” trended on the Twitter-like platform Weibo, with more than 13,000 people sharing their thoughts on the relaxation of the largest citywide lockdown in China. Many posted expressions of joy, though some expressed fear an official declaration of victory will mean memories of the city’s ordeal will be erased. “I just know that spring 2022 won’t be back,” read one post.

City officials Tuesday warned lower-level authorities that under no circumstances were they to restrict movement of people living in areas designated as low risk. A major source of public resentment during the current outbreak was that junior officials were often those implementing the most stringent measures.

People dancing on a Shanghai street Tuesday as the city prepares to exit its lockdown.

Photo: ALY SONG/REUTERS

A street in Shanghai on Tuesday. Authorities said restrictions on private vehicles will be lifted while shopping malls can run at 75% of capacity.

Photo: ALY SONG/REUTERS

The city’s largest makeshift Covid-19 treatment center closed Tuesday, a major step in returning properties taken over as part of the emergency-containment measures to their intended use. The 50,000-bed facility had been housed in one of the exhibition centers that played a central role in Shanghai commercial life before the latest outbreak brought economic activity to a halt.

A 50-point plan to accelerate the city’s recovery was unveiled by officials over the weekend, with tax cuts for companies and measures to stabilize supply chains and encourage consumption, including incentives for buyers of electric vehicles.

Chinese stocks have rallied as expectations grew that Shanghai would soon exit its lockdown, and amid signs that the government appears to have the virus mostly under control elsewhere despite pockets of infections that continue to sprout up. Shanghai’s benchmark indexes had in May their biggest monthly gain this year.

Still, any economic rebound will likely be limited because Beijing remains committed to its stringent Covid-19 containment policies, said economists, including investment bank Natixis’s Alicia García-Herrero.

Many global banks have cut their annual growth forecast for China in part because the government’s stimulus measures—including infrastructure investment and cheaper mortgages for first-time home buyers—are unlikely to fully erase the damage inflicted by the lockdowns.

Lockdowns and other Covid-control measures snarled logistics and supply chains in Shanghai, China’s most economically significant city and home to the world’s busiest port. Consumption slumped and unemployment has risen. The city alone accounts for almost 4% of China’s gross domestic product, supporting a vast hinterland of suppliers in neighboring provinces that have seen outbreaks and lockdowns of their own.

China’s National Health Commission reported 94 Covid-19 cases from May 30. More than a third of them were in Beijing and Langfang, a city in Hebei province neighboring the capital. Besides these two and Shanghai, cases were seen in six other provincial-level regions.

On May 30, Beijing reported one new infection found during mass-testing, breaking a three-day streak of zero cases detected outside the city’s quarantine and isolation system.

A makeshift Covid-19 testing booth in Shanghai on Tuesday.

Photo: alex plavevski/Shutterstock

Late that night, pandemic control officers arrived at Zhengxinyuan, a housing compound in Fengtai district, to take residents away to a secure facility after one tested positive. They returned at 4 a.m. to take away more residents, according to a local government announcement and social-media posts.

“Covid control personnel knocked at the door, what should I do?” one person living in the compound asked on Weibo, China’s Twitter-like platform.

More than 2,500 families were moved, some to a school dormitory turned into a makeshift quarantine facility, according to a video posted by a resident who was taken there.

Despite the stringent reaction to sporadic outbreaks, China’s capital continues to return to normality. In Chaoyang District, the city’s business hub, shopping malls, supermarkets and public transportation were all operating normally, although dining-in at restaurants is still not allowed.

In Jilin, the worst-affected region after Shanghai, average daily Covid-19 cases ticked up over the past 15 days. Absolute numbers—around nine—are below the trigger point for a several previous lockdowns, according to Goldman Sachs. There were 12 new cases in Dandong, a city in Liaoning province bordering North Korea, which is battling a Covid-19 surge.

Shanghai’s officials are eager to show their outbreak is finally over—and to gain some respite after weeks of crisis management.

Yin Xin, a spokeswoman for the Shanghai government, said there would no longer be a daily press briefing on Covid from Wednesday—after 90 had been held in the current outbreak.

“Many comrades have been living in the office for more than two months,” she said. “From tomorrow, everyone can return to their families. Tomorrow our city will have a new beginning.”

Workers dismantling barriers in Shanghai on Tuesday.

Photo: alex plavevski/Shutterstock

Cara You, who stepped outside without a pass for the first time in two months, said she hadn’t expected things to go back to normal until July, given the harshness of Shanghai’s restrictions.

“It feels very surreal to see so many people outside,” she said.

Ms. You spent a week in a quarantine center after testing positive for Covid-19 on April 1. She thinks she may have contracted the virus while rushing to stock up on essentials in crowded grocery stores in the days right before the citywide lockdown.

Her immediate concern after her positive test was to make sure her black cat, Jiumi, was in good hands. Overburdened community officials eventually arranged a volunteer to care for her cat, though by the time she left for a quarantine center home tests showed negative results.

Ms. You said she wants to use her newfound freedom to travel and go to the beach with Jiumi. “I just want to enjoy life,” she said.

Write to Shen Lu at shen.lu@wsj.com and Liyan Qi at liyan.qi@wsj.com