NEW DELHI — Kiran Dighavkar, a Mumbai official, realized the coronavirus could prove devastating for the city’s sprawling slum of Dharavi when he spent three hours trying to find a vacant ICU bed for a resident. By the time he found one, the patient had died. That was in April.

In July, Dharavi drew praise from the World Health Organization for its “aggressive action” in containing the pandemic.

“There are many examples from around the world that have shown that even if the outbreak is very intense, it can still be brought back under control,” WHO Director General Tedros Adhanom Ghebreyesus said at a news conference July 10, citing Dharavi’s success along with efforts by countries including Italy and South Korea.

India is third behind the United States and Brazil in confirmed coronavirus infections, but its new cases are climbing at the fastest rate in the world, according to Bloomberg News. For Dharavi to turn a corner in the midst of this crisis is a noteworthy story of customized solutions, community involvement and perseverance.

The slum’s turnaround offers both lessons and promise for other dense neighborhoods, particularly in parts of the developing world battling the pandemic. In mid-July, more than 1 million cases were reported globally in just four days, indicating its accelerating spread.

The odds were stacked against Dharavi, one of Asia’s largest slums. Mumbai had emerged as the country’s coronavirus epicenter. Hospitals were overwhelmed, and in mid-June, 99 percent of the city’s intensive care beds were occupied.

About 1 million people are packed into Dharavi’s one-square-mile area. Most residents depend on community toilets used by thousands every day. India’s strict lockdown, first imposed in late March, left tens of thousands of the slum’s daily-wage residents on the verge of destitution. The situation made conventional solutions such as social distancing and contact tracing impossible to enforce.

“Dharavi was a ticking time bomb,” said Shivkumar Utture, a doctor advising the city government on coronavirus measures. “There was stigma and fear among the people.”

City officials led by Dighavkar, the assistant municipal commissioner in charge of Dharavi, charted their own course. After identifying five areas reporting the most cases, they focused on screening every house for people with fever or low oxygen levels. Local doctors were enlisted to inspire confidence among residents.

Within 10 days, 47,000 people had been screened, and 400 symptomatic people were tested for the virus, with 20 percent turning out to be positive. An additional 4,000 people, including contacts and those with co-morbidities, were placed in institutional quarantine.

Health-care camps were set up in prominent locations in the slum where people could walk in and get a free virus test. Officials urged dozens of private clinics in the area to remain open so more cases could be detected. In turn, the government provided them with protective gear and daily sanitization.

The whole exercise was a “big challenge,” said Avani Walke, one of the private doctors who volunteered. Each morning, she would set out at 8 a.m., wearing personal protective equipment in the sweltering heat, to find coronavirus cases. For the next five hours, there would be no food or water.

 In the afternoon, Walke would be at her clinic seeing a steady stream of patients, many of them worried they had contracted the virus. Details of suspected cases were shared with the civic agency for follow-up action. Nearly five dozen positive cases were identified through her clinic alone.

“I was totally drained. By the end of day, I had no strength to do anything,” said the 47-year-old mother of two teenagers.

The other critical challenge was building health infrastructure from scratch. The government-run health-care facilities inside the slum had no beds or intensive care equipment. Dighavkar and his team took over a sports complex, a park, a marriage hall and private hospitals to house quarantine and treatment facilities. On a vacant lot, they built a 200-bed hospital with oxygen beds.

Hundreds of community toilets were sanitized three times a day. Soap and water supply was regularized.

The efforts paid off. The number of new cases in July was a fifth that of May. The recovery rate is over 80 percent, and the number of active cases is under 100.

“We chased the virus,” Dighavkar said, “instead of waiting for people to report it.”

But fighting the virus wasn’t the only test facing Dharavi. A burgeoning problem was its residents’ struggle for survival as the lockdown snatched away livelihoods overnight.

Nearly 150,000 workers went back to their villages, which reduced the population somewhat. But the gap between government’s relief efforts and residents’ need remained vast. Closing it was a feat the administration could not accomplish alone. The slum’s fame — the Oscar-winning movie “Slumdog Millionaire” was shot in Dharavi — helped. Private donors and nongovernmental organizations stepped in to help.

Laxmi Ramchandra Kamble, a relief worker with the Acorn Foundation, said her group helped 1,500 households with ration kits through the lockdown months. As the economy reopens and virus numbers stabilize in Dharavi, the demand for aid has diminished.

“Factories and shops are gradually opening, and now we are distributing rations to only 15 persons a day,” she said. “Things are slowly getting better here.”

While Dharavi heaves a sigh of relief, for now, fresh dangers loom. The ongoing monsoon season means spikes in malaria and dengue cases. Then there is the possibility of a second wave of the virus. Migrant workers who had left will begin to return.

“The situation is dynamic,” Dighavkar said. “We are on top of things now but not letting our guard down.”

Tania Dutta contributed to this report.