It's called ''The 40-Year-Old Virgin" as though it were a fairy tale or, perhaps, an After School Special. And lo and behold, this enthusiastic spree of vulgarities does have a moral to impart. To quote that laureate of lust, George Michael: ''Sex is natural. Sex is good. Not everybody does it, but everybody should."
''Everybody" includes Andy Stitzer (Steve Carell), the loser who is our chaste 40-year-old. Andy's love life is like a shelf of vintage toys, sealed up tight. In the meantime, he's busy with such thrilling activities as collecting war figurines and playing his tuba.
Andy owns a Barcalounger customized with video-game controls, has a framed poster of the wimp band Asia hanging in his apartment, and watches ''Survivor" with the elderly couple in the apartment upstairs. It gets worse. Andy karaokes alone. And he pedals around the San Fernando Valley not on a studly mountain bike but on what looks like something Jan Brady might have ridden. The man is the opposite of sexy.
But the spirit of ''The 40-Year-Old Virgin" is not one of mockery, at least not exclusively. The writer and director isn't Todd Solondz, the maker of ''Welcome to the Dollhouse," who might have mined tragedy from this tale. It's Judd Apatow, who seems to harbor an affinity for losers and their eccentricities. He wrote and directed episodes of the cruelly short-lived television show ''Freaks and Geeks" and created ''Undeclared," a sharply drawn college series that also didn't last. So while Andy's predicament is a joke, the character is not.
Paul Rudd, Romany Malco, and Seth Rogen play Andy's co-workers at an electronics store (they're individually hilarious), and when they discover Andy's sexual history, they take it upon themselves to help him get some action. They encourage him to drink, to get high, to speed date, to wax his chest hair -- anything to get a woman to sleep with him. (The last instruction features the ripping away of Carell's actual chest hair.)
But Andy is profoundly torn about his quest: Does he even want to be dating? He's lived with sexual blinders for this long, and some of the women he meets are so loony it seems he might be better off alone with his tuba.
As one buddy says of Andy's virtuousness: ''What's right isn't working for you. You need to try some wrong." Like the potential one-night stand (Leslie Mann) who, in a hysterical scene, drunk-drives Andy from the bar, slurring the words to ''Get Ur Freak On" and scraping parked cars. There is similar nuttiness with Elizabeth Banks, who plays a randy employee at a bookstore in the same shopping plaza as Andy's store.
When a customer at the store gives Andy her phone number, things start looking up -- as they should since that woman is played by Catherine Keener. The movie straightens out, too. What was really just a filthy and enjoyably farcical episode of an Apatow TV show (nightmarish high-school scenario jestingly transplanted to middle age) becomes a surprising essay on the merits of maturity. It's true that Andy has never crossed home plate with a woman. But unlike his co-workers, he knows how to act like an adult.
Keener's character, Trish, is a single mother, and wouldn't you know it: Andy is more comfortable helping her raise her teenage daughter (Chelsea Smith) than he is trying to bed the girl's mother. The movie doesn't forsake its crassness, but it does acquire a heart, like a daisy that's sprouted in manure.
Apatow's direction is often haphazard. The movie's homemade look and general clumsiness only makes sense in the joyous, crude-looking finale. So, a lot of the credit for what's right with ''The 40-Year-Old Virgin" goes to the screenplay, which Carell and Apatow wrote. They like these characters and, when it matters, they dare to give them feelings, none truer than Andy's.
Carell is a former ''Daily Show" correspondent and the star of the underappreciated American-television version of ''The Office." The comic mode he perfected on both shows is desperation: tightly coiled, insecure, uncool, aloof but painfully needy. It's a shtick that Carell turns on its side for this movie. When he does so, sadness and regret spill out. He asks us to see Andy not as a virgin but as a man. In turn, we can't help but see Carell as a perceptive actor and not a clown. He's touched us for the very first time.
Wesley Morris can be reached at email@example.com.