If you’ve ever been to a memorial service where everyone is heartbroken and stricken with grief but there are just as many laughs as tears, just as many moments of wickedly dark humor as heavy sobbing — well, there’s your reference point for “Manchester by the Sea.”

This is one of the funniest films about coping with tragedy I’ve ever seen. Not that it’s a comedy, not for a second. It’s an immensely moving and beautifully resonant drama about the walking wounded and how they cope with a horrific event from many years past.

That there are major, legitimately earned laughs to be mined from such heavy material is a testament to the breathtakingly good performances by the cast and the magnificent artistry of the writer-director Kenneth Lonergan, who has crafted a masterpiece, perhaps destined to win multiple Academy Awards.

This is a story that in lesser hands could have been mired in melodrama and wrapped up with an audience-pleasing bow. Instead, and to great effect, Lonergan (director of “You Can Count on Me” and “Margaret,” screenwriter of “Gangs of New York”) has delivered a modern masterpiece reminiscent of the classic, gritty dramas of the 1970s. It’s no easy journey, but my goodness is it brilliant.

Over the last decade, Casey Affleck has quietly compiled a roster of stellar performances to match just about any actor on the planet, from “The Assassination of Jesse James by the Coward Robert Ford” and “Gone Baby Gone” (both in 2007) to “The Killer Inside Me” (2010) to “Out of the Furnace” (2013) to “Interstellar” (2014).

In “Manchester by the Sea,” he takes it to the next level in an Oscar-worthy lead performance.

Affleck plays Lee Chandler, who works as a custodian in a handful of apartment buildings in Boston. Quiet to the point of being anti-social, Lee fixes leaking showers and clogged toilets, shovels the icy sidewalks — and gets drunk every evening, sometimes ending his night with some arbitrary, self-destructive brawling in a tavern. We don’t yet know what happened to this guy, but he might as well be a zombie when it comes to engaging with humanity.

In brief, perfectly executed flashbacks, we begin to piece together the life Lee once knew. He was married to the gorgeous, loving and feisty Randi (Michelle Williams), and they had three beautiful children, and though life wasn’t easy, it sure was sweet and filled with the sounds of laughter and the warmth of love.

Suffice to say all of that is in the distant past.

When Lee’s brother Joe (Kyle Chandler) dies suddenly but not altogether unexpectedly — Joe had a heart condition and was told he probably wouldn’t live to see 50 — Lee has to return home to Manchester-by-the-Sea to take care of Joe’s funeral arrangements and to temporarily look after Joe’s 16-year-old son Patrick (Lucas Hedges) until someone takes permanent guardianship of Patrick. (The boy’s mother, an alcoholic who hasn’t been a part of his life since he was a little boy, is not a viable candidate.)

One of the many, many things “Manchester” gets just right is the dynamic between parents (and uncles, and the parents of friends) and teenagers. The adults are convinced they’re much hipper to the ways of the kids than their own parents were, the kids roll their eyes and can barely contain their glee at pulling fast ones on the adults — and the reality is somewhere in between. (I loved the moment when Patrick asks his uncle if a girl can stay over, thinking it’s just a formality. Lee says no, and when Patrick asks why, Lee says, “I don’t like her.”)

Back in his hometown, Lee is constantly reminded of the tragic circumstances that led to him leaving. C.J. Wilson is terrific as a longtime family friend who welcomes Lee back without judgment. Tate Donovan is note-perfect in a small role as Patrick’s hockey coach. Gretchen Mol is outstanding as Patrick’s mother.

Lee’s plan is to take care of the arrangements for Joe, make sure Patrick is OK and hightail it back to Boston and his empty, numbed-down life as quickly as possible. But complications ensue, and Lee can’t leave, at least for a while. He butts heads with Patrick (the fights usually subside because Patrick doesn’t have his license yet and he needs to Lee to drive him to school and to band practice at his girlfriend’s house), he tries to find temporary work to make ends meet — and he sees his ex-wife for the first time in many years.

In the most devastatingly effective scene in any film of 2016, Randi and Lee bump into each other on the street, and Randi asks for a minute of his time — and before it’s over, you’ll have to remind yourself to breathe again. It’s maybe the best work Michelle Williams has ever done.

On one level, “Manchester by the Sea” is a small movie, in that it’s about a handful of people living out their lives in their little corner of the world. With the exception of Lee, who took off for the big city not to chase dreams but to escape a nightmare, just about everyone else in this story won’t ever leave the town they were born in and will just try to do the best they can to find love, to have a family, to earn a living. Nobody here is trying to change the world or touch greatness.

But there’s also something Shakespearean about the scope of the story, and the universal emotions touched upon.

“Manchester by the Sea” is the best movie I’ve seen this year.

★★★★

Amazon Studios and Roadside Attractions present a film written and directed by Kenneth Lonergan. Rated R (for language throughout and some sexual content). Running time: 137 minutes. Opens Friday at local theaters.