SÉRGIO CABRAL became governor of the state of Rio de Janeiro in 2007 during one of its periodic security crises, with criminals attacking police stations, burning buses and hijacking cars. But rather than send trigger-happy police into the favelas (self-built slums) controlled by drug gangs in retaliation, he prepared the state’s first sensible security policy in decades, focused on community policing. Mr Cabral’s election coincided with an economic recovery in Brazil’s former capital after decades of decline. The award of the 2016 Olympics seemed to set the seal on Rio’s revival and its governor’s success. The state is safer than for many years. But Mr Cabral is now Brazil’s least popular governor. After being re-elected in 2010 with 66% of the vote, his approval rating has slumped to 12%. Protesters calling for his resignation were camped outside his home for weeks. He had intended to step down in April to campaign for Congress; now he may leave in December rather than continue to taint his deputy and would-be successor, Luiz Pezão.

The street protests against poor public services and corruption that swept Brazil in June hurt the public standing of all the country’s politicians. Mr Cabral suffered more than most, says Ricardo Sennes of Prospectiva, a political consultancy, partly because Rio’s voters are becoming less willing to overlook scandal in the search for safety. Mr Cabral is close to Fernando Cavendish, a businessman whose construction firm was accused of paying kickbacks last year. In July it was revealed that Mr Cabral uses a state-owned helicopter to commute ten kilometres (six miles) to work and to weekends at his beach house, costing taxpayers 3.8m reais ($1.7m) a year.

But the main reason for Mr Cabral’s dimming popularity is that the euphoria that accompanied the new security policy is giving way to a more realistic assessment. The security strategy involves taking back territory rather than confronting gangs head-on. First, special forces dislodge gang leaders and search for drugs and weapons. Then a permanent police station, called a “Pacifying Police Unit” (UPP in the Portuguese acronym), is set up, staffed by officers trained in community policing who patrol around the clock. Since 2008, 34 UPPs have been put in place (see map). Six more are planned before Rio hosts the final of the football World Cup next July.

Rio has recently seen reminders of the bad old policing. In June, after an officer was shot dead when a protest march degenerated into looting, special forces entered Complexo da Maré, a vast favela on the road to Rio’s international airport. In the ensuing gun battle nine people were killed, at least two of them bystanders. Police say their response was proportionate; residents, that it was indiscriminate revenge for the death of one of their own.

The disappearance in July of a labourer after he was taken for questioning to the UPP in Rocinha, Rio’s biggest favela, highlighted a worrying rise in cases of people going missing in pacified areas. That may merely reflect better statistics: in the past many disappearances went unreported for fear of reprisals from the gangsters responsible. But the state now pays the police bonuses for killing fewer people (some previous governors rewarded police kills), leading to fears that some officers may have switched from recording “deaths while resisting arrest”, as the police traditionally disguised their murders, to simply disposing of the evidence. Some of Rocinha’s officers have been suspended and its commander replaced.

An oft-heard complaint is that UPPs benefit well-off areas most. By 2016, when Rio hosts the Olympic games, their coverage will still be largely restricted to favelas that surround richer beach districts and the sporting venues, or line strategic roads. The city had to start somewhere, counters Colonel Frederico Caldas, the officer in charge of the UPP programme. Rushing would have stretched police too thin and risked failures, bringing the whole endeavour into disrepute.

Rio’s poorer districts are starting to realise that they may have to wait a decade or more before getting a UPP. Meanwhile, they fear an influx of displaced criminals. Baixada Fluminense, a sprawl of poor suburbs where the state’s biggest gang, the Comando Vermelho, is active, has seen an upsurge in murders and carjackings.

The police try to stop criminals migrating, says Colonel Caldas: for the weeks before the taking of a favela they monitor access routes and those of nearby areas occupied by the same gang. The pacification of Rocinha in 2011, for example, led to the arrest of its druglord as he tried to flee. The only study on crime migration suggests this is limited: a count of arrests in Niterói, a city across the bay, in 2012 found that only 5% were of outsiders.

Not all favelas find life after pacification equally profitable. In the four years since Chapéu Mangueira and Babilônia, twin favelas close to Copacabana beach, got their UPP, new apartments have been built and streets paved, named and numbered. Postmen and taxis are now willing to enter. Hostels with panoramic views do good business; Bar do David, a restaurant, has made it into the city’s guidebooks. But communities in less favoured areas cannot replace drug money with tourism. Crackdowns on petty offences such as driving a mototaxi without a licence cut post-pacification earnings, too.

The biggest complaint of residents in pacified favelas is that though the violence has receded and gun-toting gangsters can no longer saunter through the streets, they still lack decent schools, housing and health care, as well as jobs. “The main lesson is to have patience,” says Lieutenant Paula Apulchro, who commands the Chapéu Mangueira and Babilônia UPP, where public services have noticeably improved. “It’s only after the UPP that those other good things can come.” Elections in Rio used to be all about making the streets a bit safer. Mr Cabral’s achievement is that his successor will have to offer more.