We have a sad, damaged family that is barely functional, with parental supervision at a minimum. A peculiar stranger with distinct musical tastes sweeps into the house, takes control, behaves in an unorthodox manner, and helps the family heal before moving on. You’re thinking “Mary Poppins,” but no — it’s “Hesher,” a dark, weird, and wholly unique comedy that uses a bucketful of obscenity to help the sweetness go down.

The Forney family has suffered a loss, leaving Paul (Rainn Wilson), the dad, depressed and couch-bound, and the 13-year-old son, T.J. (Devin Brochu), completely rudderless. They live with T.J.’s grandmother (Piper Laurie), who is descending into senility. The cast on T.J.’s arm and the wrecked car sitting outside the house are reminders of the accident that shattered their lives. At school, T.J. is bullied, but he hardly cares.

Into this gloomy scenario comes a ray of sunshine by the name of Hesher (Joseph Gordon-Levitt), a long-haired heavy-metal dirtbag who drives a van and is frequently shirtless and usually vulgar, who has on his chest a tattoo of a stick-figure man shooting himself in the head. Hesher may or may not be an older student at T.J.’s school, may or may not by a pyromaniac, may or may not be named Hesher. At first he appears randomly in T.J.’s life, suddenly materializing like a specter, accompanied by a distorted guitar riff on the soundtrack. Then he moves in to the Forney family’s garage, fixes himself a bowl of cereal, and strips down to his tighty-whiteys so he can do laundry. Grandma is too dotty to notice, Paul too morose to care, T.J. too terrified to object.

Who is this provocateur, this agent of chaos, this harbinger of doom? He is Hesher.

He does not bring doom, however, but peace, kind of. He becomes something of a guardian and big brother to T.J., albeit one who is without sentiment or inhibition. When he sees that T.J. has a crush on a frumpy young supermarket cashier, Nicole (Natalie Portman), his “romantic” advice to him is unrepeatable. In fact, much of what Hesher says should not be repeated in mixed company, nor his actions duplicated in any company. (Let us just say that Hesher is not opposed to senseless but satisfying vandalism.) His presence in the Forney home eventually prods T.J. and Paul into communicating with one another about their grief so that they can move beyond the tragedy.

Yes, Hesher teaches the Forneys how to love again. The story at the core of this often hilarious film is familiar, but it has been adorned in a bizarre, immensely pleasurable costume. It’s essentially “Mary Poppins,” as I said; it’s also every other story in which an outsider comes to town and stirs up the locals until they learn something valuable. First-time feature director Spencer Susser, who co-wrote the screenplay with David Michod (whose own “Animal Kingdom” was about a very different dysfunctional family), is confident enough in his material and in his actors not to overplay the situation’s “quirkiness.” Hesher is what he is and does what he does, without comment from the filmmaker — no “Get a load of this guy! Eh? Eh?” underscoring. Hesher doesn’t care what you think, and Susser has a lot of fun with that attitude.

So does Joseph Gordon-Levitt, whose list of interesting character choices continues to grow. Hesher is the sort of belligerent vulgarian that David Cross excelled at playing on “Mr. Show,” yet Gordon-Levitt expands him into someone we can watch for 90 minutes. Without betraying the character’s enigmatic charm — part of the fun is not knowing where the hell this guy came from — Gordon-Levitt gives him a few gentle touches of humanity, particularly in his scenes with Piper Laurie’s grandmother character.

The film’s protagonist is T.J., though, not Hesher, and young Devin Brochu is an outstanding find in that role. He astutely conveys the pain and frustration of a pre-adolescent boy, and more than holds his own against the more experienced actors who surround him.

“Hesher” is a comedy, mostly, and a loony, anarchic one at that. It revels in the flagrantly antisocial behavior of its title character and delights in appalling us. But it also has dramatic underpinnings that come through with surprising sensitivity. Don’t focus on what you’ve lost, Hesher says. Focus on what you still have! That’s an ennobling sentiment, and no less so for being conveyed through an anecdote that relates to Hesher’s genitalia.

B+ (1 hr., 40 min.; R, pervasive harsh profanity, graphic sexual dialogue.)