The sweltering favelas of Rio De Janeiro may seem a long way from Baghdad, but lessons learned during the American occupation of Iraq are rapidly being adopted by Brazilian police as they descend into the slums of the country’s second largest city. Brazil’s attempt to reassert state authority over these lawless areas faces resistance from both protesting civilians and armed insurgents, as residents resentful of decades of neglect wage a parallel campaign to criminal gangs protecting their revenue streams. In the face of these challenges, authorities are borrowing liberally from the American counterinsurgency manual as they attempt to win the hearts and minds of Brazil’s poorest citizens.

Roughly four percent of Brazil’s population inhabit the favelas, with criminal gangs and drug-dealers blending easily amidst a sea of 10 million people. Though the neighborhoods began as little more than shanty towns, they now consist of miles of densely packed structures built according to the whims of local residents and the availability of cheap construction materials. First inhabitated by decommissioned soldiers, the favelas underwent rapid expansion in the early 20th century as farm workers and peasants were lured to urban centers during Brazil’s period of industrialization. Many homes lack basic amenities — including 30% lacking proper sanitation — but residents are fiercely defensive of their territories, in part because they represent one of the few urban areas where housing remains affordable to the poor.

To understand both the favelas and Brazil, you must first return to the period in the 1970s when Brazilian democracy was overthrown in favor of a US-backed military dictatorship. Opposition to the regime began as a peaceful protest movement, but a campaign of imprisonment and torture against government opponents soon gave birth to a violent underground guerrilla movement. Mass arrests of rebels and their sympathizers lead to an influx of Marxist intellectuals and democratic agitators into the country’s crowded prisons, where political prisoners served their terms alongside common criminals. Contrary to the regime’s expectations, the ‘politicals’ remained unbroken by the notoriously tough prisons and instead provided their cellmates with a crash-course on political theory and revolutionary organizing. Upon release, many of these former prisoners would return to the favelas and use them as a base for anti-government activities including bombings and kidnappings.

The first serious attempt to to deal with the problem of the favelas involved physically bulldozing houses within the impoverished areas, with the stated intent of driving the poor into the suburbs. The campaign was eventually discontinued as the now-organized criminals armed and mobilized swathes of the community, transforming marginal gangs into heavily armed militias. The poorly paid and demoralized Brazilian police forces, out-gunned and suffering heavy casualties in the dense warren of streets, eventually gave up the campaign and returned to their barracks. This strategic withdrawal allowed armed gangs to replace the state in providing its foremost function: establishing security and justice for its citizens. Instead of turning to police and courts, the residents would instead rely upon heavily armed cartels dispensing street-level justice, held together through a complex system of local patronage.

As with many South American insurgencies, the winding down of the Cold War lead Brazil’s urban guerrillas to abandon their struggle for violent political change. Some, like current President Dilma Russouf, would re-enter mainstream Brazilian politics after the restoration of democracy and achieve considerable success. Yet more groups would abandon political pretenses entirely, choosing instead to continue their kidnappings and extortion solely for profit. The organization and discipline acquired during the revolutionary struggle would aid them considerably in dominating the traditional criminal enterprises of drug running and arms trafficking.

Some of these groups, like the notorious Comando Vermelho (“Red Command”), continue to combine their criminal acts with social advocacy and have entrenched themselves within local communities. Their move away from politics has been accompanied by a concurrent increase in brutality; torture and mutilation has become a widespread tactic, and residents suspected of ‘collaboration’ with police are often subject to gruesome fates. Journalists responsible for unsympathetic articles in local news are also targeted — in 2002, famous producer and investigative reporter Tim Lopes was dismembered before being burned alive by a Red Command cell.

In contrast to disastrous failed efforts in the 70s and 80s, the current campaign to regain control of the favelas is an aggressive attempt to provide residents with both physical security and essential social services. The police brigade spearheading this effort is the “Pacifying Police Force” (UPP), a specially trained unit that seeks to apply soft-power incentives alongside an armed security presence. Unlike the notoriously corrupt and ill-trained regular police force, UPP officers are offered substantial bonuses for their service in the hope that it will lessen the temptation to take bribes. In contrast to previous pacification campaigns, the UPP do not withdraw at the end of the day — they have established a permanent presence in some of the most dangerous communities and built outposts and police stations in areas that were previously considered “no-go”.

The mass-employment of UPP divisions doesn’t mean that Brazil has abandoned the ‘sharp end of the spear’ — on the contrary, its “Special Police Operations Battalion” (BOPE) has been more active than ever in bringing a violent end to suspected gang members. Operating in a method roughly analogous to US special forces, these military units utilize speed and force to eliminate the most heavily-armed targets and are often employed to soften up an area by destroying heavy weapons caches before UPP forces enter. BOPE’s high-impact tactics have earned them considerable enmity from both local populations and international rights groups such as Amnesty International, which highlight several instances where poor intelligence has lead to the unit executing innocent men.

Despite the outreach program offered by the government, the power of the gangs remains significant. Red Command and its counterparts are media-savvy and maintain an active presence on social media services like Instagram, using their network of online supporters to advertise their continued strength and threaten collaborators. They continue to provide financial backing and recording studios for artists generating ideologically friendly music, and a search for ‘Comando Vermelho’ on Youtube will produce dozens of hits for music produced by the gang. They also continue to sponsor dance halls and festivals, where enormous parties are thrown for the residents and young members are recruited. When Commando Vermelho called for a one-day strike after one of their members was killed in April of 2012, the residents obeyed, and shops and stores stayed shuttered despite police appeals.

The nearly three-decade long rule of the gangs in these areas has also left the population deeply skeptical of whether the government will demonstrate an enduring commitment to the pacification program. The UPP’s budget is scheduled until 2016, which means that funding for the unit is currently set to expire almost immediately after the end of the Olympics. While no one doubts that the criminals will still be here in two years, there is a sneaking suspicion that police interest in tackling the tough issue in the favelas will wane once the global spotlight of the World Cup and Olympics is removed.

Overall, the police and military units in Brazil have shifted away from the hardline seek-and-destroy tactics of previous decades towards a strategy favoring targeted killing alongside social and economic incentives to ‘normalize’ neighborhoods. While units like BOPE are essential for taking on deeply entrenched traffickers, their shoot-first policy has resulted in high levels of civilian casualties — 5669 Brazilians were killed by the police between 2003 and 2007 in Rio alone. The good-will of the favela population is also wearing thin in the face of heavy handed repression of protests, including a recent demonstration over a police shooting that was broken up only after police opening fired on the crowd with live ammunition.

Whether the pacification campaign can maintain its momentum throughout the World Cup and Olympics remains to be seen — nor does anyone know if it will continue thereafter. If the state gives up its hard-earned progress in providing security to these areas, the consequences for community members who have worked alongside police units may be dire indeed.