Harry Dean Stanton passed away recently, but fortunately he was given the opportunity to give a valedictory performance that will stand among his most memorable. John Carroll Lynch’s “Lucky” is very aptly titled, as far as we’re concerned: it affords Stanton the swan song he so richly deserved.

Stanton plays Lucky, an elderly man living a fiercely independent life in a small desert town. Lynch’s film introduces us to the routine he follows every morning as he rises from bed in his isolated house, does some exercises, smokes a cigarette, dresses and moseys down to the diner run by genial Joe (Barry Shabaka Henley) for breakfast as he does the newspaper crossword. Afterward he goes to the tiny grocery where he exchanges a few words with the sympathetic clerk, Bibi (Bertila Damas), and buys milk before going home to watch TV, have a few more cigarettes and finish the puzzle before making his way to the bar run by saucy Elaine (Beth Grant), where he’ll debate things with her long-time boyfriend Paulie (James Darren) and bartender Vincent (Hugo Armstrong) while commiserating with his best friend Howard (David Lynch) over the escape of his pet—really companion—an ancient tortoise called Roosevelt, which apparently took the opportunity of an open gate to amble off into the wild.

Lucky is a free spirit not only in his mode of life but his views. He’s an atheist who brusquely offers opinions about such concepts as reality, and reacts belligerently when he finds Howard, bereft over Roosevelt’s departure, conferring with an estate planner named Bobby (Ron Livingston). While he’s confirmed in his belief that nothing lies beyond death, however, he’s sufficiently concerned when he gets dizzy and takes a tumble in the kitchen that he visits his doctor, a sharp-witted and sharp-tongued gent appropriately named Kneedler (Ed Begley, Jr.). His accident also leads to expressions of concern from friends like Loretta (Yvonne Huff), the waitress at Joe’s, who actually pays him a visit at home where they share a joint while watching an old Liberace tape on TV,

And there are further unexpected changes to the established routine. A stranger (Tom Skerritt) ambles into Joe’s, and Lucky strikes up a conversation with him that leads to reminiscences about their wartime experiences—which inevitably turn toward one’s attitude in the face of death. Another transformative incident has Lucky encountering familial warmth when he accepts an invitation from Bibi to come to the big birthday bash she’s hosting for her son Juan Wayne (Ulysses Olmedo), where he meets her mother Victoria (Ana Mercedes) before joining in the festivities in an unexpected fashion. (Fortunately, the scripters sidestep the cliché of having his performances posted on YouTube.)

It’s obvious that like its protagonist, Lynch’s film meanders, but like him it also reflects on major existential questions—though, happily, not in a heavy-handed or maudlin way. The key to its ability to avoid slipping into sanctimony is of course Stanton, whose way of wryly skirting pomposity with the trace of an impish grin remains intact, though he can also deliver a serious line (or even sing a song) without mockery. He offers an endlessly endearing portrait of a sometimes irascible old man determined to live on his own terms but at the same time enjoying occasional engagement with others.

The other cast members seem happy to provide him with the opportunity to shine, though in the process they come off well, too. Grant brings her usual measure of gritty spunk to the party, and Darren, who has kept a very low profile in recent years, comes across with a turn as a semi-reformed rogue that could be career-reviving. Begley shines in his single scene, as does Skerritt (reuniting with his old “Alien” co-star), while Henley, Huff, Armstrong and Damas add warmth to their characters and Livingston, often so abrasive, has a genuinely poignant moment when Bobby and Lucky finally connect. Perhaps the biggest surprise of all, however, comes from director David Lynch, who has worked frequently with Stanton (most recently on the “Twin Peaks” revival), and brings real depth to a man contemplating mortality and freedom after the sudden departure of his beloved pet.

One has to commend Logan Sparks and Drago Sumonja for a script that allows for delicious digressions while remaining focused on illuminating a specific person, and John Carroll Lynch—a versatile character actor himself—for unfussy direction that gives his actors room to add lovely grace notes to their performances while not allowing the film to bog down. Robert Gajic’s editing obviously represents an important contribution to that balance, while Amitra Corey’s production design (especially in the interior of Lucky’s house) and Tim Suhrstedt’s cinematography help to create an ambience at once familiar and exceptional. Nor should one overlook Elvis Kuehn’s hauntingly simple score, in which Stanton plays a role as well.

“Lucky” is a small film, but it has a big heart, as well as a performance that in many respects acts as a summing-up of Stanton’s long, remarkable career. Ave atque vale!