HONG KONG—Elizabeth Liu began to sob at the dinner table one evening in late March. She had just returned from the daily Covid-19 test that was the only time her family could leave their 10th-floor Shanghai apartment.

That was when Mrs. Liu realized that the mental toll of living under China’s zero-Covid policies had become unbearable. It was also when she and her Singaporean husband agreed that by year’s end, they would leave the city where they’d met and which is the only home their four children—aged two to 12—have known.

“It had just been building, this sense of anxiety and stress,” said the 39-year-old Texan, who moved to China in 2005 and Shanghai two years later. “It got to the point where I just thought: I want to get on a plane and I don’t care who comes with me.”

Elizabeth Liu sat in a Shanghai park with her four children on June 22. She said China’s zero-Covid policies brought her a great deal of anxiety and stress.

All lockdowns are unique and everyone experiences them in their own way. Even though more than half the world has lived through some form of government Covid-19 restrictions, Shanghai’s lockdown stands apart.

The Chinese financial capital’s importance for global supply chains, as well as the challenge of applying the world’s most stringent lockdown rules to a city of 25 million people, help to show why it was unique.

But Shanghai also stands out to illustrate the human cost when China’s Covid policies go awry. Three months after authorities announced the beginning of an experimental two-phase lockdown of the city, the Journal is publishing deeply personal accounts of the ordeal from four residents. Their feelings of helplessness, isolation and despair. The mounting anxiety over basic needs such as food and safety that felt like an echo from China’s past; cascading mental health concerns; the urge to escape the city; and the risk of new lockdowns should the virus return.

Shanghai had previously been spared the worst fallout from China’s policies to keep the country Covid-free. Mrs. Liu’s church had been closed for two years because of curbs on mass gatherings and travel restrictions meant they hadn’t seen relatives back home. But the city had avoided sweeping lockdowns. Shanghai officials insisted they wouldn’t be needed as they relied on more local and focused containment measures.

But as the virus spread, so did the residential areas under lockdown.

When Mrs. Liu’s compound joined them for six days starting on March 21, no reason was given and no cases had been found. There was no warning and no time to stock the home with food and other essentials.

Deserted highways during Shanghai’s long Covid lockdown on April 7.

Photo: Qilai Shen/Bloomberg

On Sunday, March 27, authorities made a surprise announcement that a two-phase lockdown would begin the following morning. All those living to the east of the Huangpu river were ordered to stay home for four days starting the following morning; those to the west would follow four days later.

This time, Mrs. Liu had time to prepare. The local supermarket was already stripped bare of fresh food and many other items soon ran out. Still, she stocked up on flour and rice, canned and dried goods, cat litter and diapers.

“I thought: ‘I got so many noodles.’ But it wasn’t enough,” she said. “You can only prepare for what you can imagine. Things that happened were unimaginable.”

On the eve of her side of the city’s lockdown, only a few stems of ginger, garlic bulbs and rotting cucumbers were left.

April 4 came. Lockdown was extended. Days became weeks.

News that authorities had separated children from their parents sent a shock wave through the city.

Mrs. Liu and her husband discussed what they would do if any of the family tested positive.

“I was making plans to fight the police,” she said, laughing slightly. “I’m not a protester, a fighting-back kind of a person. But there is just a point where this drives you a bit insane.”

She told her husband they had to leave before the end of the year.

“People get sick in the fall,” she kept saying. “If people get sick, there will be more lockdowns and even less chance to leave.”

She is now saying farewell to friends and selling unwanted furniture.

“Everyone says: ‘Are you excited?’ But no, I’m just sad. I’m sad for the city. My city. I love this city,” she said.

Xu Ziwen stood in her kitchen in Shanghai on June 22. It was there where she joined neighbors in banging on pots to demand food from the government during the lockdown.

April 23: Xu Ziwen was frying bok choy when a couple of neighbors began banging on their cooking pots. Residents in nearby communities had done this to demand food from the government.

“I poured the bok choy out and washed the pot quickly and started to bang it,” she said.

A dozen neighbors were soon bashing pans until someone called the police. A food parcel arrived the next day.

For a moment, Ms. Xu felt a connection with neighbors she had rarely spoken to since moving from Fujian province four years ago.

“I realized that it is not just me feeling emotional. It is not just me feeling angry, feeling unhappy, feeling upset,” she said.

She’d felt for some time that Shanghainese kept their feelings to themselves. Still, that reserve was largely to her liking.

A worker collected a swab sample for a Covid test in Shanghai in April.

Photo: Qilai Shen/Bloomberg News

Life in Shanghai suited her. The 37-year-old financial manager felt free from the pressure back home to marry and have children. In Shanghai, people gave her more space.

The part of the city where she lives is peppered with coffee shops, Michelin-starred restaurants and cultural sites. She visited museums and made friends—meeting her boyfriend along the way.

“For a woman like me, unmarried and with no children, Shanghai has been more friendly,” she said.

That greater freedom soon felt like isolation as the lack of government information and worries over food stoked anxiety. She joined a neighborhood WeChat group for the first time to find out what was going on.

She only owned that one pan, otherwise she dined out of or ordered takeout. Now she couldn’t leave the apartment and Shanghai’s delivery services were overwhelmed. She spent hours in vain every day tapping food apps on her phone.

A government food package arrived on April 1: Two carrots, two white radishes, seven or eight stems of bok choy, a few potatoes and about a pound of pork. In a group purchase with neighbors, she bought a cabbage for 25 yuan—about $3.75, or 10 times the normal price.

The lockdown dragged into May. Ms. Xu demanded that the neighborhood committee send Covid-positive neighbors to the quarantine centers because one new case meant 14 more days of lockdown. But she quickly dropped her demand when she heard the rule had changed: A positive case would now doom the entire block to quarantine.

“I hope everyone gets Covid, and that will put an end to it,” she said.

Yvette Yuan sat at the entrance of her Shanghai housing compound on June 22. It was there, during lockdown, where she would wait for food deliveries that she had organized.

May 23: Yvette Yuan’s neighbor tested positive, filling the 20-year-old with despair.

Around midnight, soon after the neighbor’s positive test, she slipped out of the apartment she shares with four roommates.

“I couldn’t stand the confinement,” she said.

She wandered through the compound for almost an hour, taking in the night air to calm her mind. The guard at the front gate was asleep. She walked outside, ran a short distance, then quickly returned.

“The worst that could happen was that I would be sent back to my compound,” she said. “I was still afraid that I’d be caught.”

Still, that brief freedom made her feel alive.

“I realized that the reason why I didn’t experience any major emotional breakdown in the past two months was because I kept myself occupied,” she said.

She’d kept busy early in the lockdown with the daily struggle to secure food for her compound. With delivery services now back to normal, she had more time on her hands. And her mental health was deteriorating.

“Any little thing that didn’t go well as planned could trigger my anxiety,” she said.

Ms. Yuan had returned to China on a gap year from college in London, moving to Shanghai from Beijing in February for an internship that didn’t pan out. As supplies at her compound ran short, she volunteered to bulk-order and distribute food to residents.

“If we waited for government supplies, we’d be starving,” she said.

Yvette Yuan at a parcel drop-off point on June 22. She insisted upon leaving her mask on during the photo session because she felt it had become part of her face.

Her first order was pork. She spent 13 hours on WeChat, taking orders and answering neighbors’ questions, logging everything onto a spreadsheet. The pork arrived six days later.

Then, on April 14, a neighbor attacked Ms. Yuan. As she went with her roommates for their daily PCR tests, a man tried to cram into the elevator. Only one household at a time was allowed. After a quarrel, he backed out.

But as she lined up for the test, he came up and grabbed her by the throat, dragging her to the ground. Neighbors pulled him off. Heading back to her apartment, Ms. Yuan began to bawl uncontrollably.

“I felt so lonely and helpless,” she said.

Throwing herself back into the group purchasing helped take her mind off the incident. Still, the trauma festered. Ms. Yuan had taken all her antidepressants and her anxiety medications were running low. The prospect of running out worsened her sleep disorder.

She hadn’t seen a psychiatrist since Beijing. She needed to see a doctor to get more medication, but many hospitals and clinics were only treating Covid patients, or they had closed after experiencing outbreaks of their own. Getting permission to leave the compound had also gotten tougher.

On May 19, Ms. Yuan was given a permit to leave for an appointment at Shanghai Mental Health Center—just her second time outside the compound in almost 7 weeks. She cycled 4 miles to the clinic, wearing the full protective gear that was insisted upon by the neighborhood committee. Tired by the ride, she walked home, lingering at every green space she passed.

I can’t wait to get out,” Ms. Yuan said. “I want to take a walk from where I live all the way to the Bund”—the historical riverside walkway in central Shanghai. “Just enjoy walking, nothing else.”

Mr. Yin, who didn’t give his full name, walked through a park near his housing compound on June 22.

June 1: On being released from lockdown, Mr. Yin’s friend went out and bought a freezer to be ready for the next one.

There will be no end to lockdowns as long as everyone has to get tested every few days, he said. While most countries now put vaccination at the core of their epidemic controls, China sticks to its playbook from the early days of the pandemic in Wuhan: rapid, sweeping lockdowns, testing and quarantine for anyone infected.

Mr. Yin, who declined to be identified by his full name, had seen it up close. After moving back to Shanghai from Wuhan two years ago, he told his parents to make sure they always had enough food for two months: 50 cans of meat and fish, 130 pounds of rice.

So when his residential complex was locked down on March 17, Mr. Yin felt prepared. He felt lucky since the rules were lax where he lives and he was able to take a daily walk within the compound.

“The lockdown didn’t take that big of a toll on me mentally,” said the 43-year-old.

Quarantine workers patrolled a residential building in Shanghai in April.

Photo: Qilai Shen/Bloomberg

Many of his friends, though, panicked as their food ran out. Tempers frayed. There were quarrels and even physical fights between residents and health workers over the daily Covid tests.

“People are always in fighting mode, just like Ukraine. Except that we don’t have guns,” he said.

Drones flew overhead all day long, blaring at people to stay at home. They’d hang motionless in the air for more than 10 minutes, to make sure residents were aware of their existence.

On April 22, notices pasted on the wall of Mr. Yin’s building said that barricades would be placed at the gate of the compound. Similar barriers had sprung up across the city that week.

Mr. Yin woke up around 6 a.m. the next day.

“I was ready to fight. I was contemplating whether I should kick those fences down,” he said.

Only there were none there. Later, he heard that residents in a nearby compound had angrily criticized workers who were sent to put up the fences and the work stopped.

Anger dominated his emotions. “You feel a sense of injustice but you don’t really know who you should direct the anger at,” he said.

“Still, if more people refuse to comply and challenge the rules, that’ll make it difficult for those in power to execute the policy,” he said.

In the days and weeks that followed the official end of the lockdown, districts that are home to more than half the city’s population were again under restrictions after new Covid cases were detected.

WeChat groups in his compound sprang back to life: was it time to stockpile food again? A sense of despair was spreading, he said, as more people questioned whether the lockdowns would ever end.

He now longs to leave Shanghai—maybe even China.

“You still have a leash around your neck,” Mr. Yin said. “Only now, the leash is a bit longer.”

Write to Natasha Khan at natasha.khan@wsj.com, Cao Li at li.cao@wsj.com, Shen Lu at shen.lu@wsj.com and Stella Yifan Xie at stella.xie@wsj.com