Saying that “Me and Earl and the Dying Girl” involves two high-school outsiders and a classmate with leukemia might make it sound like a mawkish retread of “The Fault in Our Stars.” But Alfonso Gomez-Rejon’s film of Jesse Andrews’ novel (adapted by the author himself) skillfully walks a fine line between the precious and the maudlin, its initially excessive quirkiness morphing into something cheekily amusing and at times quite affecting.

Much of the film’s ability to overcome the extremely busy visual style that Gomez-Rejon and his cinematographer Chung-Hoon Chung (as well as animators Nathan O. Marsh and Edward Bursch) bring to the material is due to the likable young cast, and especially Thomas Mann as Greg Gaines, a high school senior who’s skated through the preceding four years by affably maintaining decent relationships with all the campus cliques while belonging to none of them. In fact he has only one close friend, Earl (RJ Cyler), the childhood pal with whom he’s spent years indulging their joint love of cinema by making little movies spoofing classic films (complete with groan-inducing puns for titles), and whom he joins every day for lunch in the office of cool history teacher (and movie buff) Mr. McCarthy (Jon Bernthal). He also has unusual parents. His father (Nick Offerman) is a college professor who, being tenured, putters around the house all day indulging his taste in odd foods, which he insists on sharing with Greg and Earl.

But it’s Greg’s chirpy mother (Connie Britton) who starts the plot rolling by insisting that Greg visit Rachel Kushner (Olivia Cooke), a classmate he barely knows, who’s been diagnosed with cancer. He’s welcomed effusively by her mother Denise (Molly Shannon), though Rachel herself is at first not at all interested in being the recipient of his pity, however well-intentioned. But Greg’s awkward charm and goofy take on the world gradually overcome her resistance, and the two predictably develop a genial friendship, with Earl joining as part of what becomes a trio.

The movie becomes episodic, and at times it veers dangerously in the direction of over-cuteness. The adults never register beyond the level of sketch comedy, though they’re all agreeably played by talented farceurs. And Gomez-Rejon’s proclivity for a splashy style, abetted by Chung’s camerawork—he is, of course, the man whose virtuoso moves gave such visual razzmatazz to both the original “Oldboy” and “Stoker”—sometimes threatens to go too far, especially when Marsh and Brusch’s animated segments are added to the mix.

But “Me, Earl and the Dying Girl” survives mostly unscathed, largely because the three leads keep it grounded in a semblance of reality and avoid the exaggerations that a story of this kind could so easily invite; the result could have stumbled pure coyness on the one hand or bathetic weepiness on the other. Cyler’s gruffly down-to-earth manner and Cooke’s ability to win sympathy without pleading for it are important factors. But despite their importance, the movie is largely dependent on Mann hitting the right notes, not only in performance but in his nearly ubiquitous voiceover. And he does: in his hands Greg is neither a complete geek nor a wiser-than-his-years adolescent. With all due allowance for the teen genre, Mann makes him a convincing example of a garrulous kid struggling his way toward a mature understanding of the world around him, including how to deal with real tragedy rather than the humdrum inconveniences of high school life.

“Me and Earl and the Dying Girl” will probably earn an unusually warm welcome among critics, who are going to find the comic expressions of Greg and Earl’s cinephilia in their terrible little video efforts especially amusing while more ordinary moviegoers might not even recognize some of the titles being parodied. They might also be more prone to appreciate the film’s frequently extravagant style, and its obvious homage to the high school pictures of John Hughes. But Gomez-Rejon, along with the cast and crew, have managed to make a movie that’s both warm and funny enough to satisfy the multiplex audience without degenerating into a crass farce or a sloppy tearjerker. In this day and age, that’s a considerable achievement.