Films about homeless children struggling to survive alone in the streets cannot help but carry a powerful emotional impact—as witness the first half of the recent “Lion,” though Garth Davis’ adaptation of Saroo Brierley’s novel stumbled in its second section. Nadine Labaki’s “Capernaum,” a title which translates as “Chaos,” also wields enormous resonance, though it too makes a decision at the very end that dilutes it.

Populated by non-professional actors, the film, written by Labaki and four others, centers on Zain (Zain Al Rafeea), a boy of twelve (or approximately so: his parents neglected to secure a birth certificate for him, or to celebrate his birthdays) who lives with his neglectful mother Souad (Kawthar Al Haddad) and father Selim (Fadi Kamel Youssef) in a squalid Beirut apartment with a bevy of brothers and sisters. He works as a delivery boy for Assadd (Nour el Husseini), who lusts after his favorite sister Sahar (Cedra Izzam), who is even younger than he. Zain tries to protect herm but the family’s flat is owned by Assadd’s father, and the clan seems to survive, though precariously, by mixing prescription drugs into juice and having the children sell the result to passersby on the street.

When Souad and Selim effectively sell Sahar to Assadd, Zain rebels and goes off on his own to a town on the coast. In his effort to find food and shelter, he encounters Rahil (Yordanos Shiferaw), an Ethiopian refugee who’s working a variety of jobs in order to raise her darling your son Yonas (Boluwatife Treasure Bankole, who’s actually a girl). Though in desperate straits herself—she’s trying to raise the money to buy a fake I.D. that would allow her to stay in the country legally—she befriends Zain and brings him home to take care of Yonas while she’s away at work. The three become a virtual family, though Zain clearly chafes at keeping inside the tiny flat all day.

A crisis comes when Rahil is arrested and jailed as an illegal, and Zain, not knowing where she’s gone, struggles to care for Yonas on his own. He eventually reverts to his family’s old practice or preparing extra-fortified juice to sell on the street, with only marginal success. Taking a bit of advice offered by another street child, a Syrian exile named Maysoun (Farah Hasno), he applies for assistance from a refugee agency, pretending to be Syrian himself (we see him practicing a Syrian accent, though the effect will be lost on American audiences). But when the landlord locks him and Yonas out of Rahil’s shantytown flat, he has no choice but to turn to Aspro (Alaa Chouchnieh), a shady crook who’s been trying to convince Rahil to turn Yonas over to him, presumably for sale to a family, in return for her I.D.

Returning home at long last, Zain finds his family worse off than when he’d left, and in response to a tragedy he feels more deeply than his parents do, he commits an act that lands him in juvenile detention. Unbeknownst to him, he and Rahil are very close to one another in prison.

All of this is told in flashbacks that emerge during a plot device that might disturb some viewers—a trial, presided over by an avuncular judge (Elias Khoury), in which the jailed Zain brings suit against his parents for giving him birth (and, by their recklessness and neglect, dooming him to the misery he has endured). Zain’s represented in court by Nadine, a censorious attorney played by Labaki herself, who helps him present his case forcefully, though Souad and Selim have the opportunity to say their piece as well, and while it doesn’t make them any less horrible, it does provide a bit of understanding.

The periodic court sequences interrupt the narrative flow of “Capernaum,” but a more serious problem comes at the very close, when Labaki feels compelled to add a closing montage that ends things on a positive note for not just one but several characters, while meting punishment where it’s due. As much of a relief this might provide to the audience, it doesn’t feel earned given all that’s preceded, and in particular closing the picture with a freeze-frame of Zain that can’t help but remind you of Truffaut’s “The 400 Blows” is a miscalculation, since its function is so very different.

Nonetheless Labaki and her team—particularly cinematographer Christopher Aoun—do a fine job of creating a gritty, realistic ambience under what must have been difficult practical circumstances, and her non-professional actors deliver heartbreaking performances. Al Rafeea, who actually was a delivery boy, carries the film on his slender shoulders, but he’s certainly matched by Shiferaw, who conveys the desperation of a mother torn from her child with real conviction, while Al Haddad and Youssef are equally persuasive as the boy’s conflicted parents.

Despite the connotations of its title, “Capernaum” proves an exceptionally disciplined piece of work, portraying the brutal realities of life for many, particularly children, in a land racked by political, social and economic turmoil. The attempt at an upbeat denouement might be an artistic mistake, but in human terms it’s an understandable one.