Writer-director Michael Berry has a message to deliver in “Frontera,” and like a modern Stanley Kramer he doesn’t avoid didactic heavy-handedness in doing so. But Ed Harris brings such world-weary gravitas to his role as a grieving widower, so devoted to justice that he’ll set aside his own pain to discover the truth, that he comes close to making up for the picture’s sometimes clunky narrative.

Harris is Roy, the retired sheriff of Medio County, Arizona, which straddles the boundary with Mexico. He lives with his spunky wife Olivia (Amy Madigan) on an isolated ranch that’s often crossed by undocumented migrants, one of whom is Miguel (Michael Pena). Trudging along a wash on the ranch with a companion in hopes of finding work, Miguel’s met by Olivia, who’s out riding and treats the two men with kindness, giving them water and blankets. But the three are observed by a trio of local teens out for some target practice with human beings, and a stray shot causes Olivia’s horse to rear. She hits her head on a rock in her fall, and the unfortunate Miguel is quickly charged with her murder by Roy’s successor Randall (Aden Young).

Roy, however, is unconvinced, and begins an investigation of his own, finding the spent shells from the rifle Miguel insists was firing at them. The identity of the shooter is one of the plot points that turns out, for reasons of melodramatic punch, as rather implausible, though as played by Seth Adkins the young man’s torment over the thought of what he’s done is quite affecting. What’s more significant is the way in which Roy goes about uncovering what actually happened. While gruff and taciturn—and, in one brief moment toward the start, no bleeding heart when it comes to illegal immigration—he shows himself to be a man of utmost principle, intelligence and craft, and Harris manages to convey it all without broadcasting the emotions on his well-weathered face. He’s an actor at the top of his game, gracing every film he’s in nowadays, and it’s refreshing to see him in a lead role again.

Meanwhile another plot thread is playing out in the attempt of Miguel’s pregnant wife Paulina (Eva Longoria) to cross the border with other paying customers of a lustful coyote (Julio Cesar Cedillo). Her experience turns out to be, in a way, even more horrible than what befalls her husband. But once again Roy will intervene to assist. He’ll also not only be the catalyst for a hopeful future for Miguel and Paulina, but will also act to prevent a closing tragedy that, in far too blunt a fashion, hammers home its message about the violence that mindless prejudice feeds.

That final sequence points to the central problem of “Frontera”—a war between its style and its content. On the one hand, the grittiness and honest, unforced performances, not only by Harris but by most of the cast, make for welcome visual sobriety (courtesy of the locations and Joel Ransom’s evocative cinematography) and a mood that exudes authenticity, even if it means pacing that can come across as dilatory (Larry Madaras served as editor). On the other, Berry’s desire to spell out the theme that the Mexicans crossing the border don’t deserve the sort of treatment they’re receiving from far too many callous, bigoted or greedy people (whether they be fellow countrymen like the vicious coyote or northerners like the excitement-seeking teens or the pseudo-patriot we meet briefly at the close) leads all too frequently to crudely didactic moments. There are elements in the picture that avoid slipping into the latter trap—the performances by Harris and Young most particularly. And while the characters played by Pena and Longoria, though not precisely one-dimensional, don’t possess the same degree of shading, the actors bring real feeling to them.

Thanks primarily to Harris, “Frontera” is at times dramatically arresting, but also terribly uneven, especially when judged against better films dealing with similar themes—like John Sayles’s “Lone Star,” which not coincidentally, one assumes, is set in a fictional Texas border town called Frontera. It might have been better for Berry not to have invited invidious comparisons.