SANTIAGO, Chile — It wasn't that long ago that Chilean President Sebastián Piñera boasted that the country was ready for the coronavirus. "Far better prepared than Italy," is how he put it in March.

And after locking down the population, bolstering hospitals and testing aggressively, the country did appear to be faring well against the pandemic. With a comparatively advanced health-care system, it kept numbers of cases and deaths lower than regional peers Brazil, Ecuador and Peru. By April, officials were touting plans to distribute a first-in-the-world “immunity passport,” enabling Chileans who had recovered from covid-19 to get back to work.

They now appear to have been overconfident.

After weeks of soaring infections, Chile has now reported more than 250,000 cases of the coronavirus, seventh in the world, and 4,500 deaths. Officials said over the weekend that 3,000 more deaths were probably caused by covid-19. Its 1,338.9 cases per 100,000 people lead Latin America.

As in other countries, the outbreak in this South American nation of 19 million has spread from rich to poor, increasing in devastation as it infects more vulnerable people.

Early cases were concentrated in a younger demographic in the wealthier areas of Santiago, keeping hospitalizations and deaths relatively low and leading officials to believe that the outbreak was contained. But the movement of workers across the capital soon carried the virus to poorer, overcrowded neighborhoods. The approach of imposing and lifting “dynamic” lockdowns by area proved unsuccessful.

“The government missed an early opportunity when they didn’t do enough to track contagion or isolate returning travelers in the richer northeastern suburbs — and then relaxed the lockdowns too quickly,” said Ximena Aguilera, an epidemiologist who sits on Chile’s coronavirus advisory committee.

“The gamble was that they would be able to stem the spread of the virus early,” Aguilera said. “But the strategy focused disproportionately on hospital care — when the social aspect is just as important.”

The pandemic arrived in Chile after months of demonstrations against rising inequality. The era-defining movement railed against what protesters said was the uneven distribution of gains from the country’s rapid growth in recent decades. Those differences have now been laid bare by the coronavirus.

“Although it likes to think otherwise, Chile’s DNA code is very Latin American, and its cities are highly segregated,” said Dante Contreras, an economist at the University of Chile. “Part of the population lives in the First World and the rest in the Third World; yet we all live within a few kilometers of one another. . . .

“Both the social movement and pandemic have torn away a veil, revealing a very different country to the one that Chile’s elite had thought it lived in.”

The coronavirus mortality rate in Santiago’s public hospitals has been twice that of the private clinics in the affluent northeastern reaches of the capital. Researchers showed in a recent Lancet study that Santiago is one of the most unequal capitals in terms of life expectancy in Latin America.

Down Santiago’s sloping valley in Lo Hermida, a densely packed neighborhood famed for its solidarity and self-organization, isolation policies written for Chile’s upper and middle classes seem irrelevant. Initial advice suggested that those who contract the virus isolate in separate, well-ventilated rooms and refrain from sharing bathrooms with others.

In homes where several generations live together in confined spaces, that’s not possible.

“Where are these people supposed to isolate?” asked María Araneda, a community organizer in Lo Hermida. “If one of us gets the virus then we all will, because we can’t just move into another room.”

Compounding the risk, she said, many in the neighborhood work in the informal sector, without savings or pensions to fall back on. “People . . . earn their living day to day, selling what they have at the markets or working wherever they can,” Araneda said. “Staying at home is simply not an option, because if people don’t go out and work, they don’t eat.”

Schools and universities have closed their campuses and moved classes online, but many students can’t access high-speed Internet.

Jaime Mañalich, who resigned this month as Chile’s health minister amid a barrage of criticism, acknowledged that he hadn’t appreciated the extent of poverty and overcrowding in parts of Santiago.

When the government moved in May from targeted, dynamic lockdowns to a citywide shutdown, furious hunger protests erupted in the southern suburb of El Bosque. Residents there had already been under quarantine for more than a month, and income had begun to dry up.

The government hurried the launch of a countrywide food aid program, but its narrow focus — and ostentatious deliveries accompanied by camera crews — have drawn criticism.

Araneda described the food boxes as a “Band-Aid.” She continues to run a community kitchen program, preparing meals for the people of Lo Hermida from donated food, two or three days a week.

Several stimulus packages have been announced for those struggling under lockdown. But they get at only part of the problem, according to Aguilera, the epidemiologist.

“People in the poorer neighborhoods aren’t just worse off economically, but a variety of factors make them more vulnerable to the virus,” she said. “Overcrowding complicates matters, while dietary and lifestyle factors contribute to increased incidences of illnesses such as hypertension and diabetes.”

Chile has maintained comparatively high levels of testing. But Piñera’s unpopularity after the protests last fall and a chaotic communications strategy during the outbreak have undermined the government’s response.

Officials in April were touting a return to normality while also warning that the worst of the country’s outbreak was yet to come. A senior health official said people could meet friends for coffee as long as they maintained their distance, and on April 30, when the country had confirmed 16,000 cases, a mall in Santiago became the first to reopen.

The government set a date to launch the immunity passports but quickly backtracked after the World Health Organization advised against it, saying there was no proven link between recovery and immunity.

As cases in the capital shot up, government calls for a gradual return to normality gave way to references to the Battle for Santiago. The mall shut down again.

Piñera on Saturday approved legislation to increase the penalty for violating lockdown restrictions to up to five years in prison.

With the winter beginning to bite, Chileans now face months of quarantine. As Chile passed Italy in cases, new data this week offered a glimmer of hope that its curve might finally be starting to flatten. Officials are urging Chileans not to let down their guard.

A constitutional referendum won by protesters last fall has been delayed until October. It’s expected to bring people back to the streets to protest conditions now laid bare by the outbreak.