RIO DE JANEIRO — For teachers in this seaside megacity, Rio de Janeiro’s surge in violence has meant making a life-or-death judgment call with unnerving frequency: deciding whether to cancel classes because of nearby shootouts.

For police officers, it has meant burying 119 of their own so far this year and surrendering ever more territory to drug gangs that have resumed open-air sales in teeming communities that had been declared “pacified” just a few years ago.

Many ordinary residents of this city of about 6.5 million start the day scanning mobile apps that track live reports of gunfire before planning their commutes.

A little more than a year since Rio de Janeiro hosted a largely successful Summer Olympics, Brazil’s showcase city is plagued by a rise in lawlessness reminiscent of its darkest periods in the 1980s and 1990s. There were 4,974 people killed in Rio de Janeiro State, with a population of about 16.5 million, during the first nine months of this year, up 11 percent from last year, according to state government statistics.

The rise in violent crime here is part of a nationwide trend that experts say has been exacerbated by Brazil’s economic recession, by corruption that has hollowed out government coffers and by fierce competition among drug trafficking organizations.

Last year, there were 61,619 people killed across Brazil, according to data compiled by Brazilian Forum on Public Security, making it the deadliest year on record.

Facing a budget deficit and increasingly well-armed and organized drug cartels, officials in Rio de Janeiro have turned to the federal government for a bailout and to the military for backup.

“The situation is one of complete vulnerability,” said Antônio Carlos Costa, the head of Rio de Paz, an organization that supports victims of violence. “The weapons used by the traffickers are weapons of war.”

The resurgence of violence comes after what had been tangible, but short-lived gains in reducing the city’s crime.