AS a poster boy for the new, less violent Rio de Janeiro, Diego Raimundo Silva dos Santos could hardly be improved upon.

He is good-looking, with a disarming smile and a matter-of-fact way of describing his former life as the right-hand man of one of the city's most feared drug traffickers.

When he gave himself up to police three years ago, newspapers printed a photograph of him in cuffs, wearing a fashionable T-shirt. These days, he models for the same brand.

"The first gun I got was a pistol," he told me. "After a while they could see that I used it well."

He started working for the dealers because there were no other jobs and he wanted a new pair of trainers, soon gaining the trappings of thug life: women, designer clothes, a tattoo of rapper 50 Cent across his back and an AK-47 rifle slung over his shoulder. I asked him if he had ever killed anyone.

"There were shootouts with police and other gangs, but whether I killed anyone, I don't know," he said.

His mother, an evangelical Christian, once tried to drug him with sleeping pills and smuggle him out of Complexo do Alemao, the slum where he was raised. Santos surrendered the day before the Brazilian army and military police invaded.

After spending nine months in prison for "association with drug traffickers", he got a job as a cameraman with Afro-Reggae, a non-profit organisation that promotes social change through art.

This story of a gang member made good fits neatly into the narrative of Rio's transformation from a notoriously dangerous third world city to a booming modern metropolis capable of hosting the World Cup and the Olympics. But it cannot be taken at face value. Just like reports of a new, safer Rio, the tale of Mister M is inspiring but incomplete.

This was the nickname given to Santos by his comrades in Red Command, the city's biggest, most paramilitary gang. The original Mister M was a magician on Fantastico, a popular television programme. In Alemao, Santos was known for making the bodies of his enemies disappear.

Online, he can be seen firing his machine gun as a friend chants a challenge to police: "Come up here and we'll kill you."

When the military invaded, in November 2010, images of tanks entering the slum and men with assault weapons fleeing to higher ground were broadcast all over the world. Since then, Alemao has become one of Rio's 33 "pacified" areas, known by their acronym, UPP, for Unidade de Policia Pacificadora. Across the city, around 8000 police officers have been installed in the favelas, in permanent units.

The first UPP was in Santa Marta, a community at the edge of the city's prosperous south zone. Captain Marcio Rocha, the commander there, told me that the change has been dramatic.

"Before, there were battles for control of the favela. Gangs would execute people who did something they didn't like," he said. "Most of the people who live here trust me. They have my mobile number. The interaction is real."

Before, police went into the slums to make arrests, take bribes, sell guns and they killed 1000 people in an average year.

Since the project began, the city's homicide rate has almost halved, to 24 murders per 100,000 inhabitants.

In the last four years, military police fired 100,000 fewer bullets than in the previous four. In the faded, formerly glamorous neighbourhood of Copacabana, police did not fire a single shot last year.

Jailson de Souza, who runs the non-profit-making Observatorio de Favelas, told me the primary objective of the UPPs is to improve the city's international image.

"The drug trade was creating problems for Rio de Janeiro. From the perspective of wanting to be a 'global city,' it's essential to stabilise the territory," he said. "When the gangs started to break out of the favela, to rob banks, rob or kidnap people in broad daylight, attack armed cars, then people start to feel unsafe all over Rio, and this has an adverse effect on investments."

The city's image suffered a setback last month, after a tourist couple hailed an unlicensed van in Copacabana. The driver and his mate ordered all the Brazilian passengers off, beat the man with an iron bar, and drove around all night withdrawing money from ATMs with their credit cards and taking turns to rape the woman. Days later, Mayor Eduardo Paes banned all passenger vans from the South Zone, where the majority of Rio's wealth is concentrated and where most tourists stay.

This was followed by an attack on a busload of German visitors on their way to see the famous hilltop statue of Christ the Redeemer.

Within weeks, police had taken control of the three nearest favelas.

"The Pope's visit and the influx of tourists are why we went in," said police spokesman, Colonel Frederico Caldas. More than two million Catholics are expected to attend World Youth Day in July. The Confederations Cup in June will be a dry run for the World Cup.

"The state is protecting a specific parcel of the city, to prepare it for these huge events and to attract international capital," De Souza said. "Concern for the people who live in favelas is the last thing on their minds."

This may be so, but for people living in the pacified areas, the change – freedom from fear, and in some cases increased private investment and access to public services – is not a trivial one. No-one pretends that fewer drugs are being sold. Security Secretary Jose Mariano Beltrame, the architect of the scheme, often notes that this was never the point: the UPPs are designed to take armed men off the street, reduce violence and establish security, so the state can begin to function in areas that have never had reliable public services.

Ricardo Henriques, who runs UPP Social which directs investment in pacified favelas, said the key is to create a virtuous circle of expectations.

"People who live in a state of war, confronted with violence every day, they don't think about the future," he said. "The more you create expectations for the future, the stronger the defences are against crime."

THERE are three main gangs in Rio. The largest is Red Command, followed by Pure Third Command and the Friends Of Friends. Red Command has been most affected by the UPPs because much of its territory is in the south zone.

Militias like the League of Justice have grown in strength, because they control areas in the west, far from the wealthy neighbourhoods. Last year, six people testified against militia leaders: all six have since been assassinated.

"Before, the militias used to show how powerful they were using terror. They used to shoot corpses a hundred times," said Tyndaro Menezes, a senior investigative reporter at Globo TV. "They don't do that anymore, because it attracts attention. These days they just 'disappear' people."

He said the drop in violence across Rio is the result of a tacit truce.

In Mare, the favela that used to be the first thing visitors saw on their way from the airport, before the state put up barriers, Red Command, Pure Third Command and the militias are all active.

"In the old days, it was impossible for them to operate side by side, but now they just divide the territory," Menezes said. "As long as they're all making money, there's no dispute. At the moment, any kind of violence is bad for the image of Rio, and the gangs know this, too."

Last month, there were gun battles between members of Red Command and Friends of Friends in Babilonia and Chapeu Mangueira, two favelas above Copacabana that had previously been considered model UPPs.

Last Thursday night, a shootout erupted in Mister M's old stamping ground, Complexo do Alemao. Police entering to investigate the killing of a drug trafficker named Filhao ran into gang members armed with assault rifles. The next day, the UPP commander confirmed shops in the area were refusing to serve his officers, having been ordered not to by the local drug lord.

Thirty police officers were recently jailed for their role in a corruption scheme in Morro da Providencia, the oldest favela in the city. On wiretaps, they were heard telling drug dealers where to open crack houses, advising them to dress drug runners in school uniforms and demanding a bigger cut of the profits. When I got into a taxi and asked the driver to take me there, he looked me in the eye and said: "It's too dangerous, I don't go there. You gringos are mad. You want to end up in the headlines."

Morro da Providencia is in a key strategic location in Rio, between the business district and the old port, which is being revitalised in time for the Olympics.

"It's that old story: I'll pretend I'm policing the favela, you pretend you're not selling drugs, and people from outside think 'great, there's no crime here' but nothing's changed," said Roberto Marinho, a leading member of the community association. "Before, the stray bullets used to spill into the south zone, so the UPP has made people who live there feel safe: they never have to close the shutters and hide under the bed any more. This is a positive step, but when the mayor talks about integrating the favela into the city, do you really think that's happening? The people who live there are still poor, they still don't have services."

Last year, 35 people were wounded by stray bullets in Rio, compared to 181 in the year before the programme began. In the favelas of Santa Marta, Vidigal and Morro da Providencia, parents told me how much life has improved now that they can send their children to school without worrying they might get caught in the crossfire.

Communities at the periphery complain their security needs are being ignored, but the project's finances are already stretched. It receives funds from the federal government, the state government, the city council and private investment: money many believe will dry up after the Olympics in 2016.

"Rio has an opportunity to become a safer city," Menezes said. "But it's dangerous, because if the project falls through, those 10 steps forward will become 50 steps back."