At a time when high school movies follow grotesquely raunchy patterns (see “Superbad”), this one is a pleasant surprise—a throwback, in a way, though one that indulges in shifts of tone so extreme that as a whole it doesn’t quite cohere. Still, “Charlie Bartlett” has enough high spots—as well as a charming turn by Anton Yelchin in the title role—that one’s likely to forgive its vagaries.

Yelchin plays the title character, a descendant of Ferris Bueller in terms of being a self-confident wiseacre who differs from his predecessor mainly in that he comes from a very well-off background, though his mother Marilyn (Hope Davis) is a spaced-out eccentric and his father unaccountably absent (a fact that’s explained late in the picture). Ejected from yet another posh private school for making fake Ids for the students (though in his favor his mom points out they’re of fine quality), Charlie’s forced to go to the local public campus, where his blazers and briefcase set him so apart that he naturally becomes an immediate object of abuse by the campus bully Murphy (Tyler Hilton).

But Charlie’s attitude of openness to every clique and outcast, even his tormentors, eventually wins people over, especially after, in his anxiousness to help others, he becomes a unofficial counselor to the all the students who need a willing ear, happily dispensing prescription drugs that he acquires from his own compliant shrink by describing their symptoms to the doc as his own. He also develops a teen romance with Susan (Kat Dennings), who just happens to be the daughter of Principal Gardner (Robert Downey, Jr.), a single dad and reluctant administrator recently promoted from the history faculty, and under such pressure from his superiors to establish order on campus that he’s begun drinking heavily. Charlie naturally becomes Gardner’s nemesis, not only because of the relationship with Susan but because Bartlett’s increasing popularity among all elements of the student body begins to bond them into a formidable, and potentially rebellious, force.

There’s a lot of plot threads winding about here, and they have distinctly different textures to them. The Charlie-Susan romance is conventionally sweet, but the Charlie-Marilyn relationship determinedly oddball (and the revelation about his absent father basically sentimental). The transformation of Murphy at Bartlett’s hands, from nasty jock to someone much more sensitive, is essentially farcical, but the characterization of Gardner is fundamentally serious, culminating in a scene between him and Charlie at the principal’s home that tries to blend melodrama and dark humor. The serious tone is even more pronounced in the thread focusing on a suicidal student (Mark Rendall) to whom Charlie gives some pills, where a definite cautionary tone emerges. And of course there’s a rousing last-act turn to a satisfying resolution.

The tonal shifts are often jarring, leaving you with the uncomfortable feeling that you’re being tugged in very different directions. But individually many of the picture’s parts are quite pleasurable. That’s certainly due to Gustin Nash’s facility with sharp dialogue and Jon Poll’s somewhat ragged but engaged direction, but also the cast’s winning qualities. Young Yelchin, who was impressive even in a dud like David Duchovny’s “House of D” and the best thing about “Alpha Dog” (in which he played the compliant kidnap victim) and “Fierce People,” blossoms here in the same way Matthew Broderick did early on in “Bueller” and “WarGames,” his hesitant, hangdog charm carrying the film. Downey and Davis both play to their strengths, and though Dennings is just okay, Hilton proves a crowd-pleasing hoot as the bully changed by Bartlett’s influence. Technically the film is solid without being outstanding (Paul Sarossy’s cinematography sometimes opts for overly dark compositions), but it’s certainly watchable.

The sunny comedy, sweet romance, dark humor and serious drama jockeying around in “Charlie Bartlett” aren’t always ideally melded, but the combination is made palatable by its good-natured eagerness to entertain even if its simultaneous desire to teach doesn’t quite come off. And the cast pushes it definitely into the positive column.