More than two million Americans live in prison, but American movies and television usually recoil from the reality of penal institutions. Because it’s a frequent setting in crime dramas, we all think we know what a modern penitentiary is about: it’s a place where tough men call the shots and weak men get raped in the showers. (To judge from the seething cop dialogue in these stories, homosexual rape is actually part of the sentence.) With the exception of HBO’s Oz, however, entertainment shows treat prison as a plot element, with characters on their way in or on their way out. Being trapped there for years and having to make sense of one’s captivity—which, of course, is the whole point—is something we’d rather not think about.

Hector Babenco’s impressive Brazilian drama Carandiru (which opens Friday at Landmark’s Century Centre) was shot on location in the Sao Paulo penitentiary of the same name, and culminates in a re-creation of the October 1992 riot in which police killed 111 prisoners. In the two hours leading up to this devastating climax, Babenco weaves the stories of a dozen inmates into a densely textured fabric, capturing the feel of a closed society whose members have lost their freedom yet still maintain a tenuous grip on their humanity.

Babenco had his greatest international success with Kiss of the Spider Woman (1985), another story about prison as both a reality and a state of mind, yet his personal investment in Carandiru runs deeper than that. After his Hollywood career dead-ended with At Play in the Fields of the Lord (1991), Babenco was diagnosed with lymphatic cancer; his oncologist was Drauzio Varella, who’d worked at Carandiru since 1989 and witnessed the riot and subsequent massacre. With Babenco’s encouragement, the doctor completed a novel based on his experiences, Carandiru Station, one of the best-selling titles ever published in Brazil. Varella claims he discouraged Babenco from adapting the book, considering it too grim a project for a cancer survivor. But in the movie’s press kit Babenco praises the “innocence” of the narrator in recording the prisoners’ stories and explains that he wanted to translate that sense of “respect and solidarity” to the screen.

Played by Luiz Carlos Vasconcelos, the doctor in Carandiru functions better as a narrative device than as a character. Babenco makes him an impartial witness—”Society had its judges, and I wasn’t one of them,” he remarks in voice-over—so he never really registers dramatically. But his grimy little hospital ward gives the inmates a place to let down their guard and tell their stories, which are staged in flashback and vividly define them as people. In its narrative sweep the film calls to mind City of God, Katia Lund and Fernando Meirelles’s epic crime saga set in a Brazilian ghetto (which was still in postproduction when Babenco started shooting). But the stories condensed from Varella’s book are so rich in irony and regret that they completely eclipse Lund and Meirelles’s movie; Carandiru is complex, City of God merely complicated.

The crimes for which the characters are doing time at Carandiru are generally motivated by passion rather than greed, which makes their violence at once more comprehensible and more troubling. Deusdete, a delicate young man, becomes convinced that his sister has been raped and guns down the two suspected culprits in the street. Highness, a tall and good-looking bigamist, keeps each of his wives secret from the other; after one discovers him sleeping with the other and sets their bed on fire, he takes the rap for the arson, partly to escape the tug-of-war over his affections. Antonio, a professional thief, breaks the news to his longtime partner, Claudiomiro (who’s also incarcerated at Carandiru), that his wife is having an affair with a cop; Claudiomiro’s wife turns the tables, accusing Antonio of coveting her. Even after Claudiomiro learns the truth and murders his wife and her lover, he remains suspicious of Antonio.

In a masterful extended sequence Babenco revisits many of these backstories as the prisoners’ families arrive on visiting day. Deusdete’s sister brings along a pretty friend who flirts mercilessly with Deusdete; she doesn’t seem like the type who’ll wait two decades for his release, but the sister, who has never revealed what actually happened with the two men, wants to give her brother something to live for. Highness’s first wife interrupts his conjugal visit with his second in a bizarre reprise of the confrontation that landed him in prison. And Antonio reconciles with his own wife, who was fooled by the false accusations made by Claudiomiro’s wife; together she, Antonio, and their son celebrate the boy’s fourth birthday.

Babenco uses the individual stories as tiles in a larger mosaic detailing the social structure and moral codes of the prison. At night the men refrain from using the toilets to avoid waking their cellmates. On visiting days they studiously avoid looking at each others’ female kin. Because the nine pavilions of the prison are largely unsupervised, the prisoners furnish and decorate their own cells. Disagreements are brought to Ebony, the unofficial magistrate of his pavilion, whose commonsense verdicts preserve the complainants’ dignity. The prison is a microcosm of the outside world—except that it has no prisons.

These codes of conduct figure even more prominently in Babenco’s treatment of Dagger, a hit man, and Zico, a petty thief and drug dealer. The film opens with a disorienting but highly charged scene in which Ebony tries to mediate between Dagger and another prisoner whose father Dagger murdered. The attacker is crazy with the spirit of vengeance, but Dagger stops him in his tracks by revealing that the person who commissioned the hit was the attacker’s own mother. Zico shares a cell with Deusdete, his childhood friend, and one night, delirious from crack and the ravages of AIDS, he kills Deusdete in his sleep by pouring a pan of boiling water on his face. With Ebony’s sanction, the other inmates in the pavilion band together to execute Zico, ritually stabbing him to death as they pass along a single knife. The only man who can’t bring himself to participate is Dagger, whose reluctance makes him suspect in the others’ eyes; after being visited in his dreams by Zico Dagger has an ecstatic experience at an evangelical prayer meeting.

This self-contained world seems relatively stable: two gay inmates, No Way and Lady Di, are “married” in a ceremony as sincere and joyful as the real thing, and the entire prison population gathers for a festive soccer tournament. But the sense of order and security proves illusory when a tiny infraction of the social codes—one inmate hangs his shorts on another’s clothesline—erupts into a full-scale insurrection. The warden convinces the inmates to surrender their weapons, which come raining down from the barred windows onto the concrete, but still the riot squad go ballistic, sweeping through the wing and cracking jokes as they mow down unarmed prisoners. It’s a horrifying sequence, because Babenco has succeeded in humanizing these men despite their own violent pasts. In this respect Carandiru is a lot like the photos of Iraqi prisoner abuse; it reminds us that humanity is a burden, but that once we reject it, we reject ourselves.