In my favorite episode of The X-Files, a psychic played by Peter Boyle remarks, "You know, there are worse ways to go, but I can't think of a more undignified way than autoerotic asphyxiation." Leave it to comedian Bobcat Goldthwait to write and direct a humane and moving film commencing with that very indignity, and starring a sad, silvering Robin Williams. Williams plays single dad Lance Clayton, who walks in on his teenage son Kyle (Daryl Sabara) doing the deed, and spends the rest of the movie coming to terms with the fact that his progeny is a total creep. A vulgar, misogynist pervert, Kyle is a figure not of Superbad fun, but of filial shame. Sabara, that lovable scamp from the Spy Kids series, has grown up to spy on the elderly neighbor as she undresses.

Lance, meanwhile, is a schoolteacher in the depressive vein of Alexander Payne satire: Think Matthew Broderick in Election or Paul Giamatti in Sideways. But Goldthwait shows a warm dramatic empathy for his protagonist, often missing from Payne's cinema. Lance's romance with a younger woman (Alexie Gilmore) implicates him in his son's erotic folly, but none of this is treated with disdain, even as it leads to tragedy. Lance is really trying to do the right thing, which makes it all the more poignant when he has to recognize his failures. Overhearing a co-worker's platitude that "raising a child is the toughest job you'll ever love," Williams loses it, seized by a rictus of chuckling disbelief. He hates his job. This "Robin Williams comedy" is mostly too black to count, but it reserves its scorn for the sweet lies of self-regard. Its biggest flaw is an overreliance on pop-music montage, bane of so many lesser American films. The songs eventually cease to pluck the heartstrings and start numbing them.

I wasn't sure what to expect from this movie, my only experience with Goldthwait's work being the VHS box art to Shakes the Clown, a lurid image haunting the video store memory much like that of Stephen King's It. Turns out, World's Greatest Dad is the World's Greatest Answer to the Hollywood fixations of Judd Apatow. Shot in Seattle, it's a middle-class morality play, improbably uplifting; a comeback for both Williams and the sexual honesty of his stand-up routines. To quote another funnyman's star vehicle, I'm a big fan. R.

World’s Greatest Dad

opens Friday at the Hollywood Theatre.