It's past 11 p.m. by the time police stop Claudio Alves's car on a dark street in Jardim Angela, one of Sao Paulo's poorest and most violent neighborhoods. Not that he'd been doing anything to arouse suspicions, just pulling out of a side street and being young. But he is so nervous that when he accidentally steps on an officer's polished boot he tries to get down on his knees and wipe off the dust.

Brazil's police may have a reputation for brutality, but Alves has nothing to worry about  at least not tonight. Officers ask him his age, his occupation, and whether he has tattoos or a criminal record, and then run his car license plate through the computer in their squad car. It comes up all clear and he's free to go.

But before he drives off, Alves does something that would seem unusual had not the others stopped by the same policemen tonight not done the same thing: He thanks the officers for doing their job. "I think it's good that they stopped me," he says, seemingly sincerely. "There are more police on the streets these days and the crime situation is much better than it was."

Brazil is notorious as one of the most violent societies in the world, and Sao Paulo, an unforgiving urban sprawl that is home to more than 20 million people, had long been a prime example of how lawlessness tormented the lives of law-abiding Brazilians. Today, though, Sao Paulo is a changed place. The annual murder tally for Sao Paulo state has plummeted from 12,800 in 1999 to 4,800 last year, a turnaround comparable to that of New York and Bogota, two cities famous for their successful policing programs.

And while Sao Paulo is the best example, it is not the only one: All across Brazil, homicide rates are tumbling. "For the first time in Brazilian history we have had three years in which the measures of fatal violence have fallen," says Julio Jacobo Waiselfisz, author of the Violence Map, a nationwide study of homicide rates. "There is light at the end of the tunnel."

The reasons for the recovery are varied. On a national level, the economy is growing, and lower unemployment and easier credit  along with government wealth distribution programs  have reduced the poverty rate and given some of the poorest Brazilians real hope for a better future.

More palpable are the after-effects of a nationwide weapons ban between 2003 and 2005. Some 88% of Sao Paulo's homicides are committed with guns, and the federal restriction on arms sales  short-lived though it was, after having been voted down in a referendum  meant less weapons were being sold openly. The effects were especially acute in Sao Paulo, where the state government had already stopped automatically renewing gun permits and seen the number of legally owned firearms fall from 80,000 to around 3,000.

Another measure that has helped keep the peace in Sao Paulo is a ban on late-night alcohol sales, especially at weekends. Police say almost two-thirds of homicides take place near or in illegal or unlicensed bars and clubs, and more than half take place between Friday night and Sunday morning. Nineteen municipalities in the state have limited the sale of alcohol at night and small towns across the country have followed suit.

But perhaps the most crucial factor both in Sao Paulo and elsewhere has been a move toward more high-profile and intelligent policing. Sao Paulo has 10,000 more officers on the street than it did in 2000, and their movements are now governed largely by the same kind of computer programs pioneered by the New York Police Department during the 1990s. By cataloguing past events, police have a clearer idea of where and when future crimes might take place and can utilise their resources accordingly. "Police today don't go on patrol," says Ronaldo Marzagao, Sao Paulo's Secretary for Public Security. "They have a computer program that tells the squad cars where to go at what time, and what crimes take priority in each sector."

One of the priorities for the police here in Jardim Angela is making themselves visible. They have reached out to the community by visiting businesses, setting up a free library in the local police station and even helping out at an orphanage. Their outreach program convinced many bars in one area to close down voluntarily after 10 p.m. and tonight, as they wind their SUVs through the dimly lit streets, they stop people as much to get to know them as search for drugs or guns. "The primordial factor here is that they don't see us as the enemy and we don't see them as the enemy," says local officer Capt. Gilberto Tardochi.

Residents would agree with that. The high-profile patrols have made residents feel more secure, and the statistics back that up. The number of homicides in the area fell from 448 in 2000 to 98 last year. Getting hauled over at as they make their way home at night is the price they pay. "It's fair, it's cool," says Geraldo Duarte, a 43-year old metro worker stopped on his way to a prayer meeting. "It's for our own security."