Six months after Rio de Janeiro hosted the Olympic Games and poured tens of millions of dollars into security to make the streets safer, the turf war between police and organized criminal gangs for control of the city's slums appears to be over.

The cash-strapped police have ceded power to the drug-trafficking gangs who operate unfettered in some areas and enforce their own rules in the favelas.

"Police used to patrol the streets, but they don't anymore. They stick to the main roads," says Renata, a resident of the Rocinha favela, who asked to be identified only by her first name for fear of reprisals.

"There are places where people will sit and openly sell marijuana and coke; the police don't go there."

In the grips of a financial crisis that was aggravated by Olympic overspending, Brazil has slashed budgets, including implementing a 20-year cap on social spending to try to reduce its massive debt. The spending limits affect every public sector, including education, health, housing and policing.

Civil servants protest the Rio de Janeiro state government's plan to limit public spending in front of the state assembly back on Nov. 16, 2016. (Ricardo Moraes/Reuters)

The recession that began in 2015 has left the country without the resources to counter the growing power of the gangs.

"I think that many of the factions see opportunity in Rio," said Robert Muggah, director of public security think-tank Igarape.

Budget cuts

Already one of Latin America's largest cocaine markets and with crumbling public security, Rio is lucrative territory for gangs capitalizing on cocaine demand from the country's middle class, which grew dramatically in the years prior to the financial crisis.

The police pacification units are still operating in the city's favelas, but the big budget cut they received after the Olympics has left them spread thin. And the state's civil police continue to go on strike in some areas over salary demands, with military police voicing similar dissatisfaction.

Military police officer uniforms hang in front of the entrance to the police battalion in Rio during a protest for better salaries earlier this month. (Ricardo Moraes/Reuters)

Meanwhile, the Primeiro Comando da Capital (PCC), Brazil's biggest drug-trafficking gang, has moved in to Rio — a recipe for violent conflict as the gangs fight amongst themselves over territory.

Brazilian President Michel Temer has ordered 9,000 soldiers to patrol Rio's streets after a military police strike in the neighbouring state of Espirito Santo triggered a lethal crime wave earlier this month. It's seen as a preventative measure should military police in Rio go on strike as well and to deny any chance of the gangs extending their reach beyond the favelas, which the military police don't patrol.

"There's law of the state is one law, and the law of the periphery is another," said Davi, referring to the unofficial laws at work in his gang-controlled favela, Rocinha. "If you do something wrong, you are punished."

'Dominated by the criminals'

Rocinha fell under PCC control only months after the Olympic Games ended. For Davi, like many other residents, the change in the ruling gang was barely noticeable.

More than 3,000 Brazilian security forces backed by armoured vehicles swept into Rocinha in November 2011 to take back control from the drug gangs. (Felipe Dana/Associated Press)

In other favelas, the battle for power has been more violent. Prazeres, a small favela in Rio's tourist-friendly downtown area, was one of many that became a battleground between the PCC and the Rio-based Comando Vermelho (CV) in 2016. Though now firmly under the control of the CV, Brazil's second-largest gang, Prazeres is constantly under threat of violent outbreaks because it's surrounded by dozens of smaller favelas controlled by different gangs.

"In Prazeres, the police have a small area where they stay, but the rest is dominated by the criminals," said Gabriel, a resident who asked to be identified only by his first name to protect his safety. "They patrol where they are allowed to patrol by the gang. There's an agreement: they go where they are allowed, or there are shootouts."

A view of the Rocinha, where residents say gangsters have taken control of the community from police, who've been spread thin because of the country's financial crisis. (Bruno Kelly/Reuters)

The prison problem

There are also concerns the battles between rival gangs going on inside the country's prisons could spill over the walls.

After the introduction of stricter drug laws in 2006, Brazil's prison population grew by 480 per cent to 622,202 by 2014. The country now has the fourth largest prison population in the world, with inmates forced to pledge allegiance to gangs as soon as they arrive.

The first month of 2017 was marred by a series of violent riots inside prisons in Brazil's northeast. Within three weeks, more than 140 inmates had been killed — many of them were reportedly decapitated.

Inmates were photographed on penitentiary roofs wielding makeshift weapons and flags with the symbol of the PCC.

Inmates are seen with weapons during an uprising at Alcacuz prison in Natal on Jan. 20. (Nacho Doce/Reuters)

State authorities quickly attributed the violence to the PCC's rivalry with the CV, after a breakdown in a 23-year-long agreement between the gangs. Between them, the two groups deliver most of the cocaine supplied to Europe, Africa and Asia, and the PCC has been expanding its territorial claims within Brazil.

"The PCC doesn't typically like to compete violently," Igarape's Muggah said, "but there's a fear right now that we're entering into a new era of violent competition between these factions."

Lincoln Gakiya, a senior state prosecutor in Sao Paulo's organized crime unit and a leading authority on the PCC, says the prison violence has many Brazilians afraid the same bloodshed could break out in the streets.

"This has already happened in some states," he said.

Gakiya points to the northeastern city of Natal where public buses were set on fire, police bases attacked and gang members murdered in the streets after the riots in Alcacuz prison back in January.

The fact that the expanding prison population is a recruiting ground for the gangs is compounding the problem.

"The policy of mass incarceration does nothing more than strengthen the hand of the factions," Muggah said.

"The very policies that have been produced to wage the war on drugs are reinforcing the power and influence of the criminal factions that inhabit the prisons, both in and outside."