Anyone familiar with Pete Davidson, either as a cast member on “Saturday Night Live” or from his appearances in the gossip columns during his brief engagement to pop star Ariana Grande, has seen the hints of tragedy behind his stoner-guy comedy persona.

That tragic shadow takes center stage in director Judd Apatow’s comedy-drama “The King of Staten Island,” a sometimes funny, often heartbreaking story that uses semi-autobiography to let Davidson exorcise his personal demons.

Davidson plays Scott Carlin, who at 24 is stuck in his life in Staten Island, New York’s least-gentrified borough. Still living at home with his mom, Margie (Marisa Tomei), a nurse, he spends most of his time hanging out with his pot-smoking pals, who sell prescription pills on the side. He also spends time with Kelsey (Bel Powley), in a relationship that a decade ago would have been labeled “friends with benefits” — in which Scott shrugs off Kelsey’s attempts to examine where all this time together and occasional sex is going.

Scott is a budding tattoo artist who has used his buddies’ skins as canvases, even though, as his friend Richie (Lou Wilson) says, “Your work is mad inconsistent.” Scott has a dream of opening a tattoo parlor/restaurant — an idea everyone tells him is gross — but he makes zero effort to make the dream a reality.

The root of Scott’s depression, we’re told early in the film, is that when Scott was 7 years old, his firefighter father, Stan, was killed while trying to rescue people from a burning hotel. Scott reveres his dad as a hero, though the reality is more complicated. (In real life, Davidson’s father, Scott, was a Brooklyn firefighter who was killed when the World Trade Center towers collapsed on 9/11. The movie is dedicated to his memory.)

Scott knows he’s messed up — he jokes about the medications he’s taking, and the movie’s first scene depicts a suicide attempt — but doesn’t feel under any pressure to do anything about it, which is how depression often works. Two events combine to kick him into action: His little sister, Claire (Maude Apatow), graduates from high school and leaves for college to escape Scott’s emotional black hole; and Margie starts dating a firefighter, Ray (played by comedian Bill Burr).

The script — written by Apatow, Davidson and comedian Dave Sirus — dives deeper into the emotions of depression, malaise and survivor’s guilt than most mainstream movies dare. Davidson, as a writer, seems as eager to confront these issues as his character wants to avoid them.

And while this is Scott’s story, Apatow gives space to explore how Scott’s problems affect the women in his life — Margie, Kelsey and especially Claire, the sibling who’s tired of walking on eggshells. Tomei and Powley are excellent, and Maude Apatow (the daughter of the director and actress Leslie Mann, and who made her movie debut at age 10 as Mann’s daughter in Apatow’s “Knocked Up”) is blossoming into an engaging, sensitive young actress.

Davidson, surrounded by a solid supporting cast that includes Steve Buscemi and Pamela Adlon, gives a breakthrough performance here that’s by turns funny and touching. In past movies, like the 2019 Sundance entry “Big Time Adolescence,” Davidson has been difficult to take in large doses. He’s grating at first here — it’s the nature of the character — but slowly, as the man-child comes to grips with his history and realizes he has to grow up, Davidson evolves into an empathetic, even charming, screen presence.

This has been Apatow’s gift: to take an abrasive comic figure — Seth Rogen in “Knocked Up,” Amy Schumer in “Trainwreck” and now Davidson — and reveal the bruised, tender heart inside. You will go into “The King of Staten Island” laughing at Davidson’s character, and Davidson himself, but in the end, you’ll be rooting for both to make it through.

★★★1/2
’The King of Staten Island’
Comedian Pete Davidson gets personal in this comedy-drama about a young man whose life is stuck in neutral.
Where • Video-on-demand rental, for $19.99, on most streaming platforms.
When • Available starting Friday, June 12.
Rated • R for language and drug use throughout, sexual content and some violence/bloody images.
Running time • 137 minutes.