Residents of Mangueira, a poor neighbourhood atop a hill outside Rio de Janeiro, watched from their rooftops as the Olympics' opening-ceremony fireworks erupted from Maracanã stadium. They don't always have clean water or proper sanitation, but some of Rio's poorest people –residents of "favelas" like Mangueira – enjoy the best views in the city.
Only a few years ago it seemed possible that these favelas – once deemed no-go areas – could be toured by Olympic visitors. Thanks largely to a profound change in strategy that also led to a sharp decrease in killings by police, Rio had made real progress in reducing crime.
And in its bid to host the Olympics, the Brazilian government vowed that the games would act "as a big catalyst" for long-term security improvements in Rio de Janeiro. For a while, that promise seemed attainable.
But in 2013, progress stalled. Homicides bounced back after several years of decline. Soon after, killings by police began to rise again. Last year, Rio police killed 645 people, three-quarters of them black, according to the cops' own figures.
What happened? To find out, I just spent six months interviewing more than 30 police officers and dozens of other officials. They speak of an ambitious policing programme that began well but is now crumbling under the weight of impunity and corruption.
For many decades, Rio de Janeiro has been a city divided between favelas and the more-affluent neighbourhoods that favela residents call the "asphalt," where residents enjoy proper streets, mail delivery, rubbish collection, and all the basic public services that most people in the 21<sup>st Century take for granted.
Drug gangs armed with automatic weapons control most of Rio´s favelas. Police engage them in military-style raids that often kill suspects and bystanders. While some of these killings have doubtless been in legitimate self-defence, many others have been extrajudicial executions.
Several shocking cases of police corruption, torture, and extrajudicial killing received wide publicity, and the newborn, fragile trust between police and residents crumbled.
Two police officers – whom I'll call Danilo and João – told me they had taken part in several operations designed to kill, not arrest, suspected gang members. During one of such incidents, an officer approached an injured man who was lying on the ground and shot him dead point-blank, Danilo recollects.
In another, João´s unit ambushed suspects, fired at them without warning, and let an injured man bleed out onto the ground for 40 minutes before finally taking him to the hospital, where he died, according to João.
He admitted such operations do nothing to dismantle drug organisations. "We go into the favela, kill 20 criminals, and another 20 take their place tomorrow. It´s like trying to dry ice."
In 2008, Rio began trying something different. In a few favelas, police established stations focused on community policing, called Pacifying Police Units (UPPs). Officers took a less violent stance and got to know members of the community. Killings by police and violent crime dropped dramatically in communities with UPPs, and 38 such units still operate. So peaceful did some favelas become that inhabitants could actually envision Olympic visitors touring them.
"The main accomplishment of UPP is to protect us from the police," a resident of the Morro da Providência favela told me. "We no longer have a death squad going up the favela and killing people."
But starting in 2013, some of the police officers working in UPPs reverted to type. Several shocking cases of police corruption, torture, and extrajudicial killings received wide publicity, and the newborn, fragile trust between police and residents crumbled. "UPPs bring a promise of change, of community policing," Major Marcio Rodrigues, commander of the UPP in the Mangueira favela, told me, "but when residents see police doing the same thing as before, we lose their trust".
Once the spiral starts, it is difficult to stop. UPP police kill more people, making it harder for them to persuade local residents to report crimes, provide tip-offs, and come forward as witnesses. Traffickers take advantage of the increasing isolation of UPPs to reclaim territory, and residents are caught in the middle of shoot-outs between the two sides.
Unlawful killings and other police abuses continue because those responsible are rarely brought to justice. The civil police are charged with investigating them but in most cases they do the job half-heartedly. The ultimate responsibility for that failure lies with Rio´s Attorney General´s Office, which has legal authority to oversee the work of police investigators and to carry out its own investigations.
The tens of thousands of additional security personnel deployed to protect the Olympic and tourist sites are expected to leave Rio shortly after the end of the games. Most residents of its favelas will continue to live in fear of both drug traffickers and the police.
Rio badly needs its communities and police to build mutual trust and respect. The best way to do that is to prosecute police for the abuses they commit.
César Muñoz Acebes is senior Brazil researcher at Human Rights Watch. Follow him on Twitter @_Cesar_Munoz