Pia Angelo, a 9-year-old girl, has recently passed away and is laid to rest in a cemetery. Her father, Jose Angelo, portrayed by Wagner Moura, finds himself in dire straits as he is pursued by the corrupt Brazilian police, ultimately leading to his arrest. Just before his capture, Jose cleverly discards one of Pia's old purses into a garbage truck, concealing something significant inside it.
The garbage truck makes its way to a dump site, where it unloads its contents. Among the debris are three streetwise Brazilian teenagers: Raphael, played by Rickson Tevez, Gardo, portrayed by Eduardo Luis, and Rat (Jun-Jun), played by Gabriel Weinstein. These rag-pickers survive by scavenging through the trash for anything valuable, sorting useful items for recycling and other purposes. At just 14 years old, both Gardo and Raphael are paid less than the standard wage due to their youth.
One fateful day, the boys stumble upon Jose's wallet in the garbage dump. Inside, they find cash, a key, and an animal lottery, along with Jose's ID card. Meanwhile, Jose suffers brutal torture at the hands of the police, who are after the contents of the wallet—though the true nature of these items remains elusive. As the police offer R 1000 for the return of the wallet, claiming it holds clues to a crime, a policeman named Federico takes notice of Raphael and Gardo, inquiring about their names.
Despite the officer's apparent interest, Raphael remains skeptical and knows that the wallet may hold deeper secrets he is determined to explore. They enlist Rat's help, who lives in the sewers due to a contagious skin disease that excludes him from the Favella. Raphael promises Rat an equal share of the potential reward for his assistance in solving the mystery. Rat deduces that the key opens a railway locker, compelling Gardo to distract the police by committing a minor theft. While the police are preoccupied, Rat and Raphael access the locker, where they find a letter addressed to a prisoner named Joao Clemente, an attorney and social activist.
Unfortunately, neither boy can read, leaving them baffled about the letter's full contents. They are fortunate to have support from Father Juilliard, a priest, and Olivia, a compassionate NGO worker who assists the rag-pickers, as they both represent the only trustworthy figures in their lives. Utilizing Olivia's laptop, the kids learn that Clemente has a background as a lawyer and activist who campaigned for the rights of marginalized communities, only to be jailed by the corrupt politician Santos.
Gardo dreams of claiming the reward for finding the wallet, but Raphael insists on meeting Clemente first to discover the truth. Meanwhile, the police intensify their pursuit for the wallet at the garbage dump. Inspector Federico Gonz grows suspicious when the boys miss work, and he resorts to interrogating Raphael with brutal tactics, tossing him around in a police cruiser, inflicting numerous injuries.
As Gardo seeks Father Juilliard's assistance to find Raphael, the police deny any cooperation, claiming that minors are not processed at that station. Despite Federico's relentless abuse, Raphael remains tight-lipped about the wallet. Eventually, a lack of support from his colleagues spares his life.
Raphael shares information with Rat and Gardo about Federico's conversations regarding the corrupt politician Santos. They resolve to leverage Olivia's connections to meet Clemente by presenting themselves as family to the imprisoned lawyer. During a visit to Santos's beachfront property, they discover from his gardener that Jose had been a trusted confidant who stole R 10 million from Santos. When Santos was away, Jose had filled trash bags with the stolen funds and concealed them in a broken fridge.
The plot thickens when Gardo and Olivia finally meet Clemente, who reveals a shocking truth: Jose was indeed his nephew. Clemente explains that the numbers in the letter hint at the location of the hidden money. Alarmingly, Santos learns about Olivia's visit to Clemente and orders Federico back to the garbage dump.
As the situation escalates, Federico discovers Pia's wallet in Olivia's possession and swiftly arrests her. In a ruthless display of authority, the police retaliate against the needy community by setting fire to the dump due to their perceived lack of cooperation. Just as the boys are close to deciphering the hiding place of the money, Federico's forces seize control of the situation. However, the code leads them to St. Francis cemetery, where it is revealed that Pia is alive, secreted away in the cemetery while her casket conceals the stolen R 10 million.
Federico arrives at the cemetery only to be confronted by the boys, who have discovered Pia. In a dramatic twist, Pia intervenes and incapacitates Federico, allowing the boys to escape with her, the money, and the incriminating book. They return to the dump and decide to secretly share some of their newfound wealth with Father Juilliard, alongside the book, so he may continue his charitable efforts. Intending to make a difference, they scatter a portion of the money throughout the dump and take a fraction for themselves.
Ultimately, Father Juilliard teams up with Olivia to publish the information contained within the book online, attracting the attention of CNN. Their efforts lead to the arrest of Santos and his corrupt associates, including the vile Federico, bringing a measure of justice to the community.