BRASÍLIA—For Victor Melo, the end began with a stolen iPhone.

The 16-year-old had spent a balmy Saturday afternoon in May with his high school friends at a funk music party in Brasília’s central park, not far from the country’s presidential palace.

As he headed home shortly after sundown, someone in the crowd grabbed his classmate Ágatha from behind and snatched her phone, witnesses told police. She spun around and saw Victor. Believing him to be the thief, she screamed out for help. Her friends knocked him to the ground and began to beat him.

Hearing Ágatha’s shrieks, another group of partygoers presumed he must be the same teen who had swiped a pair of sunglasses from them earlier. One of them jammed a broken bottle into Victor’s stomach. A young blond woman known as Apple punctured him repeatedly with what police believe was a screwdriver, skewering the muscles between his ribs. A man then plunged a knife into his heart.

In the half-hour it took the group of 20 mostly high-school students to kill Victor, no one searched him for the stolen items. Another 100 or so partygoers looked on and did nothing, investigators said.