RIO DE JANEIRO  In a quick and decisive military sweep, Brazilian security forces seized control of this city’s most notorious slum on Sunday, claiming victory in a weeklong battle against drug gangs that has claimed dozens of lives.

By early afternoon the military police had raised the flags of Brazil and Rio de Janeiro atop a building on the highest hill in the Alemão shantytown complex, providing a rare moment of catharsis and celebration in a decades-long battle to rid this city’s violent slums of drug gangs.

An air of calm and relief swept through the neighborhood, as residents opened their windows and began walking the streets. Dozens of children ran from their houses in shorts and bikinis to plunge into a swimming pool that had belonged to a gang leader, even as the police searched for drugs one floor below.

“We knew about this but we were never allowed to come in,” said one child, who identified himself as Alan, age 3, as he splashed about happily.