With a population of 100,000 people, it is one of the largest favelas in the Brazilian city and has become something of a tourist destination for visitors wanting to see the poorer parts of Rio.
Police said they had been fired at while on patrol in Complexo do Alemao. The officers alleged that the two dead youths had links to drug trafficking.
"They use radios to tell each other where there's a patrol and when they spot a small group of officers, they give orders to attack," a local policeman told O Globo.
Shootings continue to be frequent in the area, despite the fact that the Complexo do Alemao was among the first favelas to be "pacified".
Soldiers first moved into the shanty town in 2010, and in 2012 a permanent police presence was established in the area.
For the preceding decades, the area had been a virtual no-go zone for the security forces.
Security has been one of the main concerns for the Brazilian authorities during the World Cup and thousands of extra troops and police have been deployed to guarantee the safety of visitors and residents alike.