Health officials put the toll at 20, with seven hospitalized, while police counted another victim -- a female bystander felled by a stray bullet.
Military police said they came under gunfire as they approached the northern Rio slum called Vila Cruzeiro in the early morning hours with the mission of locating and arresting "criminal leaders."
The toll nearly doubled from the initially reported 11 deaths as more bodies were uncovered in the aftermath.
Police said at least 11 of the dead were "suspects."
At least 19 schools in the area closed because of the gunfire, residents said.
Police helicopters were also struck by bullets during the deadly exchange.
Police often carry out raids in Rio's teeming slums in a bid to fight drug trafficking.
This time, they said they were looking for gang leaders from other parts of Brazil hiding out in Vila Cruzeiro.
"It was an operation planned for weeks, but we identified criminal movements during the night and decided to intervene," said team member Colonel Luiz Henrique Marinho Pires.
He said the suspects were readying to move to another favela.
This was the deadliest police raid since 28 people died a year ago in a favela called Jacarezinho -- the largest such toll in the city's history.
Vila Cruzeiro, a favela crowded onto a hillside not far from Rio de Janeiro's international airport, was also the scene of a violent confrontation in February, when police killed eight people.
Tuesday's pre-dawn raid targeted the Comando Vermelho, or Red Command, one of Brazil's most powerful crime gangs "responsible for more than 80 percent of the shootings in Rio," a police spokesman told TV Globo.
Officers seized 13 assault rifles, four pistols, 20 motorcycles and 10 cars in the raid.
No arrests were reported.
The operation was criticized in some quarters for its use of overwhelming force.
"Another massacre. Schools closed, thousands of people terrorized," tweeted left-wing city councilman Tarcisio Motta.
"The policy of extermination runs its course in Rio."
Residents and activists have often denounced official abuse, including extrajudicial killings of suspects, which they say often goes unpunished.
"These operations in the favelas put the entire population at risk and prevent the functioning of public services. We know they would never be tolerated in upscale neighborhoods," Guilherme Pimentel, a public defender, told AFP.
Rio police officers were meant to start wearing cameras on their uniforms this month to film all acts in the line of duty, but use of the equipment has been postponed.
Security experts believe cameras may help prevent abuse but will not solve all the problems, and their introduction should be accompanied by comprehensive police reform.
Experts advocate for abandoning confrontation in the endless fight against drug trafficking, with a focus instead on disrupting the gangs' money flow.
"Rio needs a new public safety policy that is not the bullet," Human Rights Watch said.
Brazilian police are among the world's deadliest, responsible for more than 6,100 fatalities in 2021 -- an average of 17 per day, according to a violence monitor count.