RIO DE JANEIRO  Leonardo Bento longed for vengeance after a policeman killed his brother five years ago. So when he heard that the new “peace police” force in the City of God slum was offering free karate classes, Mr. Bento signed up, hoping he would at least get to beat up the karate instructor.

But the unexpected happened. Eduardo da Silva, the police instructor, won him over with humor and a handshake. “I began to realize that the policeman in front of me was just a human being and not the monster I had imagined in my head,” Mr. Bento, 22, said.

Years of hate and mistrust are thawing in some of Rio’s most violent slums. Pushed to alleviate security concerns before the city’s double-billing on the international stage  the 2014 World Cup and the 2016 Olympic Games  Rio officials have embarked on an ambitious plan to wrest control of the slums, or favelas, from ruthless drug gangs who ruled for years with big guns and abject terror.

The peace officers are central to that effort, flooding in after the military police clear the streets in gun battles that can last weeks. Their job is part traditional policing, part social work. They devote themselves to winning over residents scarred by decades of violence  some at the hands of the police. And the tips fed to them from those who support their efforts, officers say, help them keep the relative peace.