Bullets flying from the Morro dos Macacos ("Monkey Hill" in Portuguese) slum in northern Rio de Janeiro tore into the helicopter and hit the pilot in the leg as he hovered above the shootout, causing him to lose control and crash.
Two officers died, while the pilot and three other policemen escaped after the craft hit the ground on a football field and burst into flames. The pilot and a second officer suffered burns and bullet wounds. The other two officers also were burned, one gravely, said Mario Sergio Duarte, head of Rio state's military police.
Officials did not know whether the gangs targeted the helicopter or whether it was hit by stray bullets, but the event underscored security concerns that have dogged Brazil's second-largest city for decades.
Despite the mayhem, officials defended Rio's ability to control violence ahead of the Olympics as well as before 2014, when Brazil will host the World Cup soccer tournament with key games in Rio.
"In choosing the city, they already knew about the work that's being carried out and will continue in the area of (crime) prevention," Justice Minister Tarso Genro told the state-run Agencia Brasil news agency.
Rio state Gov. Sergio Cabral grimly told reporters that Rio's security challenges can't be cured "by magic in the short term," but he said money is being poured into programs to reduce crime and authorities are prepared to mount an overwhelming security presence at the sporting events to ensure safety.
"We told the International Olympic Committee that this won't be an easy thing, and they know that," Cabral said. "We can put 40,000 people on the streets - federal, state and municipal police - and pull off the event."
Duarte said it was unlikely that traffickers fired an anti-aircraft missile at the helicopter, though such weapons have been found in the hideouts of Rio's drug traffickers along with other heavy, military-grade arms such as grenade launchers and .50-caliber machine guns.
The pilot was able to make a somewhat controlled, though extremely rough landing, which would have been unlikely if the aircraft had been hit by a heavy weapon, Duarte said.
Police said 10 presumed traffickers were killed during the fighting in the slum, including three suspects found dead inside a vehicle. Officials gave no details on how the other seven died.
They said at least eight buses were set on fire in nearby slums as the shootouts raged. Television images showed motorists fleeing for cover as automatic-weapons fire crackled in broad daylight amid the worst violence the city has seen in months.
Images broadcast by Globo TV showed flames shooting from the helicopter wreckage, with little more than charred pieces and an intact tail remaining after the fire was doused.
Rio police frequently use helicopters to take on gangs that dominate drug trafficking in the city's more than 1,000 slums, but were unable to say whether this was the first time one of their helicopters had been shot down by gang members.
The crash happened about five miles (eight kilometers) southwest of one of the zones where Rio's 2016 Olympics will be located. The city on Oct. 2 was picked over Chicago, Madrid and Tokyo to host the games. Rio alone among the bid cities was highlighted for security concerns ahead of the International Olympic Committee vote.
The downing of the helicopter happened amid intense firefights involving rival gangs in the slum as one tried to seize a rival's territory, authorities said.
Police moved into the area before dawn, though gunfire continued throughout the day, keeping terrorized residents inside their homes as bullets slammed into apartment buildings. Duarte said late in the day that the areas were under control, and television images showed people walking in the streets at dusk in the affected areas.
Despite increased policing efforts, Rio remains one of the world's most dangerous cities. The violence generally is contained within slum areas, though it sometimes spills into posh beach neighborhoods and periodically shuts down the highway that links the international airport to tourist destinations.
Brazilian President Luiz Inacio Lula da Silva and other officials have played down the threat of violence for the Olympics, saying Rio has repeatedly demonstrated it can pull off big events without risk to players and spectators.
Rio held the Pan-American Games in 2007 without major incidents, deploying more than 15,000 specially trained officers to keep the peace.
Associated Press Writers Marco Sibaja in Brasilia, Brazil; and Alan Clendenning and Bradley Brooks in Sao Paulo, contributed to this report.