NITERÓI, Brazil — Patrícia Acioli, a judge known for imprisoning corrupt police officers, pulled into the driveway of her home one August night in this city across the bay from Rio de Janeiro. Her pursuers arrived at the same time. Then they did their work, shooting her 21 times until her body lay crumpled in the seat of her car.

“I rushed outside after hearing the shots,” said her son, Mike Chagas, 20, a college student. “No one should ever have the experience of seeing their own mother shot to death on their doorstep.

“I knew immediately that she had been killed because of her work,” he said.

Hours before she was gunned down, Judge Acioli had issued arrest warrants for three police officers accused of killing an unarmed 18-year-old man in a favela, or slum, part of a group of officers being investigated for forming an extermination squad. The same three men would later be arrested in connection with her murder, along with eight others in the police force.

Their testimony in court here, describing in chilling detail how they tracked Judge Acioli and plotted for months to kill her, has revealed a disturbing aspect of Rio de Janeiro’s newly assertive security policies, a cornerstone of its efforts to secure the city before playing host to the 2014 World Cup and 2016 Summer Olympics.