If ever proof were needed that it’s not the story, but the way in which it’s told, that matters, “Manchester by the Sea” provides it. The basic premise—about an irresponsible man who suddenly finds himself saddled with the task of looking after a youngster—is one that’s been used innumerable times, in fare ranging from syrupy Hallmark Hall of Fame-style tearjerkers to lousy comedies like Adam Sandler’s “Big Daddy.” Playwright Kenneth Lonergan’s third film—the first since “Margaret,” which was tied up for years in legal wrangles over the final cut before it got a limited release in 2011—differs from them all. In the hands of Lonergan and his exceptional cast, the deceptively simple story becomes a shattering tale of shared grief that carries a powerful weight of emotional truth. With all due respect to “You Can Count On Me” and “Margaret” (which was extraordinarily rich even in its compromised form), this is not only his best film, but one of the year’s best as well.

Lonergan constructs the film like a puzzle, shifting from present to past and back again to reveal, gradually, the whole picture. Lee Chandler (Casey Affleck) is introduced as a quietly sullen Boston maintenance man, who goes about his task of servicing several apartment buildings with a dogged efficiency broken only when he encounters any hint of complaint from a tenant. His tendency to break his usual laconic manner and abruptly lash out continues into his off hours, which he ordinarily spends alone in bars, nursing a beer: sometimes he’ll get into a fight over some perceived slight from another patron.

As flashbacks show, however, Lee was once a reasonably happy fellow in upstate Manchester, having an agreeable time with his older brother Joe (Kyle Chandler) and his young son Patrick (Ben O’Brien) on their boat, drinking with pals in the basement converted into a rec room, getting cozy with his wife Randi (Michelle Williams), doting on their young kids. They also reveal that though still a young man, Joe was diagnosed with congestive heart failure, a fact that led his high-string wife Elise (Gretchen Mol) to abandon him and their son. It’s not until the film is nearly at the half-way point, however, that we’re told—in a flashback of heartbreaking understatement—how Lee’s life came crashing down and why he is now so damaged.

Until that sequence Lonergan concentrates on the new tragedy Lee has to face—Joe’s sudden collapse, which forces him to drive up from Boston to the Manchester hospital. There he finds that his brother has died, and that he must tell Patrick (Lucas Hedges), now a rambunctious teen, of his father’s passing. Once again Lonergan stages the scene with remarkable sensitivity, from across an ice rink where the boy is practicing with his hockey team, as though it were a family matter on which it would be unseemly to intrude.

Patrick will react to the news with youthful bravado, going on with his usual activities—balancing two girlfriends, practicing with his bad rock band, arguing over “Star Wars” minutiae with his friends—while accompanying Lee in making arrangements for the funeral. But a major shock comes when they visit the lawyer’s office and learn that Joe has named Lee as the boy’s legal guardian. It’s a responsibility Lee feels totally incapable of assuming, and Patrick is no happier with the idea of having to leave town for Boston.

At this point one might expect “Manchester by the Sea” to devolve into a story of redemption, as Lee and Patrick are both saved by bonding with one another. But Lonergan is too acute an observer of life to go that route; he knows that there are wounds that cannot be so easily healed. That becomes clear when Patrick visits Elise, the mother he hasn’t seen in years, and her new husband (Matthew Broderick), hoping they might take him in, and even more so when Lee encounters Randi on the street, the baby she’s had with her second husband in a carriage, and they have a conversation of a sort that’s a small masterpiece of writing, direction and acting. The best one can expect, the film suggests, is a series of compromises—not the sort of message designed to warm the heart, perhaps, but one that’s real rather than fabricated.

The power of “Manchester by the Sea” rests on Lonergan’s script and direction, but their promise is realized by an extraordinary cast. Affleck is the anchor. His characteristic restraint and reticence can sometimes seem a drawback, but in this case they fit the character of Lee perfectly, creating a figure of apparent mildness that conceals both abiding sadness and coiled intensity. It’s an unforgettable turn. He’s matched by Hedges, who captures the combination of heedless energy and submerged apprehension that marks so many teens. Williams has less of an opportunity to shine, but her final scene alone creates an indelible impression. Chandler’s regular-guy persona also stands out, and Mol and Broderick play out their lunch sequence with the requisite stiffness. Mention should also be made of the sense of place achieved by the technical team—production designer Ruth De Jong, art director Jourdan Henderson, set decorator Florencia Martin and costume designer Melissa Toth; they fashion a totally lived-in ambience that cinematographer Jody Lee Lipes exploits—along with the gritty locations—to the full.

Some might quibble about Jennifer Lame’s editing or the music selections by Linda Cohen that accompany Lesley Barber’s original score. But the abrupt shifts in time are part of Lonergan’s narrative strategy, and one quickly accustoms oneself to them. And while Albinoni’s “Adagio” might seem an unfortunate choice, given its overuse elsewhere, it fits, as do the other music cuts.

It might seem from all this that the “Manchester by the Sea” is a downer of the first order, but it’s not. Lonergan leavens the darkness with a good deal of offhanded humor, once again of the sort that reflects how people like these really act and talk, elements that arise naturally out of the situations rather than out of the conventions of situation comedy. You leave the film not depressed but impressed by its clear-eyed honesty about characters who suffer terrible tragedies they must somehow learn to deal with.

Pauline Kael wrote about another film, “I’m a little afraid to say how good I think ‘Shoot the Moon’ is—I don’t want to set up the kind of bad magic that might cause people to say that they were led to expect so much that they were disappointed.” Critics are often faced with that possibility, and it certainly did work against “Shoot the Moon,” and more recently against “Boyhood.” So let’s end with something more low-key: “Manchester by the Sea” is as good as Angelina Jolie’s “By the Sea” was bad. If you’ve seen her film, you’ll know that’s high praise.