Taking place over the course of over two decades, City of God tells the story of Cidade de Deus (Portuguese for City of God), a lower class quarter west of Rio de Janeiro. The film is told from the viewpoint of a boy named Rocket (Busca pé in Portuguese) who grows up there as a fishmonger's son, and demonstrates the desperation and violence inherent in the slums. Based on a real story, the movie depicts drug abuse, violent crime, and a boy's struggle to free himself from the slums' grasp.
The movie begins cinematically depicting chickens being prepared for a meal. A chicken escapes and as an armed gang chases after it bumps into Rocket who believes that the gang wants to kill him. The movie then flashes back ten years earlier, to tell the story of how he got himself into that position.
Three "hoodlums", "The Tender Trio", one being Rocket's brother, Goose, are terrorizing local businesses with armed holdups. In Robin Hood fashion they split part of the loot with the citizens of City of God and are protected by them. Li'l Dice is a hanger-on who convinces them to hold up a motel and rob its occupants. Li'l Dice ("Dadinho" in Portuguese), serving as lookout, fires a warning shot, then proceeds to slaughter the inhabitants. The massacre brings on the attention of the police forcing the three to quit their criminal ways. Each meets an untimely end, except one who decides to join the church. Goose, Rocket's brother, is slain by Li'l Dice after robbing the younger boy and his friend Benny who have been hiding out and committing crimes themselves.
The movie fast forwards a number of years. Li'l Dice now calls himself Li'l Zé ("Zé Pequeno" in Portuguese), and, along with his childhood friend Benny, he establishes a drug empire by eliminating all of the competition except for a drug dealer named Carrot ("Cenoura" in Portuguese). Meanwhile, Rocket has become a part of the "Groovies" a hippie-like group of youth that enjoy smoking pot. He begins his photography career shooting his friends, especially one girl that he is infatuated with, but who is dating another boy.
A relative peace has come over City of God under the reign of Li'l Zé who plans to eliminate his last rival, Carrot, against the judgment of his best friend Benny, who is keeping the peace. At one point, his best friend and partner in crime Benny has decided to become a "playboy" and becomes the "coolest guy in City of God". Eventually, along with the girl that he has wooed away from Rocket, he decides to leave the criminal life behind to live on a farm. However, he is gunned down at his going away party by former drug dealer, Blackie, who is actually aiming for Li'l Zé. Benny was the only thing keeping Li'l Ze from taking over Carrot's business, so now Carrot is in danger.
Li'l Zé humiliates a peace loving man Knockout Ned at the party and afterwards rapes his girlfriend and kills Ned's uncle and younger brother. Ned turns violent and sides with Carrot. After killing one of Li'l Ze's men, Ned starts a war between the two rival factions that creates a "Vietnam" of City of God. Jealous of Ned's notoriety in the newspapers, Li'l Zé has Rocket take photos of himself and his gang which, unknown to Rocket, are taken by a reporter and published in the daily paper. Rocket then mistakenly fears for his life believing that Li'l Zé will want to kill him for it. In actuality, Li'l Zé is pleased with his newfound fame.
Coming full circle, Rocket is startled by Li'l Zé's request that he take a picture of the gang which had been chasing the chicken at the beginning of the film. Before he can, however, a gunfight ensues between the two gangs, but is broken up by the police. Ned is killed by a boy who has infiltrated his gang to avenge his father, who was killed by Ned during a bank robbery. Li'l Zé and Carrot are arrested and Carrot is taken away to be shown to the press. Li'l Zé is shaken down for money, humiliated and finally released, all of which is secretly photographed by Rocket. After the cops leave, the Runts (a gang of young children who robbed and terrorized the local merchants) come upon Li'l Zé and shoot and kill him in retribution for him killing one of their gang earlier in the film. Rocket takes pictures of Li'l Zé's dead body and goes to the newspaper.
Rocket is seen in the newspaper office looking at all of his photographs through a magnifying glass, and deciding whether or not to put the pictures of the crooked cops in the newspaper, or the picture of Ze's dead body. The photos of the cops would make him famous but put him in danger, while the photos of Li'l Zé would guarantee him a job at the paper. He decides to take the safe route and gives the paper the picture of Li'l Zé's bullet-ridden body, which runs on the front page.
The story ends with the Runts walking around the City of God, making a hit list of the dealers they plan to kill to take over their drug business.