Two weeks after Rio de Janeiro celebrated winning the 2016 Olympic Games, the Brazilian city was tonight bracing itself for a further night of violence after an intense gun battle erupted in one of the city's favelas and a police helicopter was shot down, killing two officers.

The violence, intense even by Rio's standards, began in the Morro dos Macacos, a hillside area in northern Rio. The shanty town, controlled by the Amigos dos Amigos (Friends of Friends) drug faction, one of three heavily-armed cocaine gangs that control many of Rio's 1,000-odd slums, was reportedly invaded in the early hours of Saturday morning by members of a rival gang, the Red Command. Police say traffickers from the Red Command were attempting to seize control of the local cocaine trade.

Deafening volleys of automatic gunfire were captured on amateur video, filmed from apartment blocks surrounding the slum. One local newspaper declared it a "War in Rio" on its website.

"We were terrified," Cristina Soares, a 17-year-old resident, told the Rio tabloid newspaper Extra as she fled the area yesterday. "The children were so scared they wanted to leave the house in the middle of all the shooting. Later on things are going to get even worse."

Mario Vilson, another resident of the Morro dos Macacos, told the news website Terra that he had been woken up by the sound of shooting. "This war has been going on for 20 years and will never end," he said. "It's very sad. I just don't know when we will have peace."

Hundreds of police officers descended on the area following the invasion. By Saturday night the death toll, including the two dead police officers, stood at 12 according to Rio's security secretary José Mariano Beltrame. Five other officers had been shot and two slum residents injured, police said.

Favela residents were gathering their belongings and fleeing their homes while at least 10 buses were set on fire across town, causing close to £1m in damage according to one company.

"I saw two bodies lying in the street, surrounded by people," said Douglas Engle, a photographer who was at the Morro dos Macacos. "Then a third body was brought down from the slum by police, wrapped in a hammock. People were standing around crying."

In the most high-profile incident, the pilot of a military police helicopter was shot in the leg as he flew over the favela and the helicopter exploded in flames as it crash-landed on a nearby football pitch. Two of those on board were killed. It was the first time a police helicopter had been shot down in Rio.

Rio's mayor, Eduardo Paes, said it was "inadmissible that Rio be confronted by delinquents in this way" and threw his weight behind police attempts to control the violence.

The head of the military police, Mario Sérgio Duarte, said the drug traffickers would "be the victims of their own choices". "We have lost two professionals who dedicated themselves to the defence of the population. But we will not be motivated by revenge," he added.

Oderlei Santos, spokesman for Rio's military police, said: "Our operations will only cease when these criminals are captured, arrested or are killed in combat."

Authorities cancelled all police leave and members of Rio's civil police gathered at the police HQ in central Rio this afternoon. They were expected to occupy a number of favelas around the city. Tonight, military police were seen entering at least one slum controlled by the Red Command in Rio's southern beach district.

The latest round of violence underlines the challenges local authorities face as they attempt to improve security before the city hosts the 2014 World Cup and the 2016 Olympics. Rio's government has spent the past year expelling drug gangs and vigilantes from four slums and setting up "pacification" projects by which the slums are permanently occupied by police.

But the majority of the city's favelas are still controlled by members of three drug factions, which possess an increasingly sophisticated arsenal, including anti-aircraft guns and automatic rifles, often sourced from inventory intended for the Bolivian and Argentinian armies and smuggled into Rio.

Faced with an increasingly well-armed enemy, Rio's police are also investing heavily in military equipment. They now have a bulletproof helicopter, while local journalists wear bulletproof vests when working in the slums. Each year, Rio's police kill around 1,000 people "resisting arrest". Nearly 90 officers have been killed this year.

Santos promised that things would improve before the Olympics. "We have a lot of time before the World Cup and the Olympics, and before then we will certainly arrest a lot of criminals," he said.