In terms of narrative there’s an afterschool special quality to “The Diary of a Teenage Girl,” which might be described as a cautionary tale about how an impressionable fifteen-year old can enjoy indulging in sex with a much older man when a societal atmosphere of permissiveness and her dysfunctional family life offer her no guidance or support. What’s unusual about Marielle Heller’s adaptation of Phoebe Gloeckner’s semi-autobiographical graphic novel is that it doesn’t mute the rawness of the tale, or paint the characters in bland, simplistic colors. The film remains a cautionary tale, but an edgy, compelling one that’s often hard to watch and even harder to forget.

Bel Powley gives a career-making performance as Minnie Goetz, a precocious, articulate, artistically-inclined teen in 1970s San Francisco. Her mother Charlotte (Kristen Wiig), is very much a child of the time and place, engaging in a freewheeling lifestyle featuring drugs and boozing that leaves little time for bringing up Minnie and her disapproving younger sister Gretel (Abigail Wait). The girls get somewhat sterner—though ineffectual—treatment from their stepfather Pascal (Christopher Meloni), who’s separated from Charlotte but still has occasional meetings with them. But a more regular presence is Monroe (Alexander Skarsgard), Charlotte’s current boyfriend, a handsome, laid-back fellow whose bemused mellowness often seems an oasis of stability in the fraught household.

Minnie may not be the most beautiful kid, but she and her buddy Kimmie (Madeleine Waters) are eager to experiment in the sexual revolution of the era. Giggling conspiratorially, they dress up to look older than they are and go off to parties and clubs where they hope to find love—or at least somebody interested in taking them to bed, whether it be a likable guy or a world-wise young lesbian, Tabatha (Margarita Levieva). And Minnie is rather forward at school as well, looking for action with Ricky (Austin Lyon), a well-to-do classmate, and Chuck (Quinn Nagle), a genial skateboarder, so forcefully that she scares them off.

Minnie’s intensity extends to Monroe, who’s sometimes lolling about in the Goetz apartment watching TV and snacking. At first he’s nonplussed by her advances, but it doesn’t take him long to consider the opportunity one that’s too inviting to resist, and soon they’re spending considerable time at his place. Minnie is so ecstatic over the loss of her virginity that she uses a borrowed cassette tape recorder to keep a diary of her amorous adventure. That, of course, will prove a major mistake.

Heller and her production team—designer Jonah Markowitz, art director Emily K. Rolph, set decorator Susan Alegria and costumer Carmen Grande—do a fine job of establishing a period atmosphere without unduly calling attention to their work, and cinematographer Brandon Trost gives the visuals a gritty, washed-out look that’s appropriate to the atmosphere of heady but skuzzy hedonism. But what sets “Diary” apart is its sense of emotional balance, which manages to present its tricky scenario in gritty, realistic terms without sensationalizing it. The intimate sequences between Minnie and Monroe are telling but treated with sensitivity, and the use of animation—in a semi-psychedelic style derived from Minnie’s own artistic efforts (as well as “H.R. Pufnstuf,” an excerpt from which is shown flickering on a TV screen at one point)—serves as an effective counterpoint to what’s happening in the girl’s real life experiences. The picture also manages an undercurrent of humor, though obviously it’s of the dark variety.

The picture’s major success, however, lies in the complexity it brings to the main characters, none of whom is turned into a simple cliché. Powley brings a compelling combination of drive and vulnerability to Minnie, showing her as no passive victim but in many respects the instigator of her ill-fated relationship with Monroe—a youngster so hungry for love that she confuses it with lust and allows her delusion of romance to take over. Rarely has the turbulent inner life of a teenage girl been depicted on screen with such directness and honesty. But equally subtle is the portrait Heller and Skarsgard draw of Monroe as a wayward man-child who takes advantage of a situation that he might not initiate but certainly embraces when the opportunity arises. While one can’t forget what he’s doing, Monroe isn’t depicted as a conniving predator but a man as lost in the ethos of his time and place as Charlotte, the neglectful mother sharply drawn by Wiig, is. It’s one of the most insightful portrayals of a dangerous but conflicted individual caught up in such a potentially explosive situation since Brian Cox’s brilliant turn in the sadly underappreciated “L.I.E.”

And so, thanks to Heller’s obvious commitment and the efforts of a superlative cast, “The Diary of a Teenage Girl” emerges as a cautionary tale with bite, an afterschool special that transcends its paint-by-the-numbers roots to emerge as a provocative, realistic portrayal of teen sexuality.