For a movie with such a distasteful premise, “The Switch” is refreshingly funny and surprisingly sweet. It’s about a man whose platonic lady friend is being artificially inseminated, who secretly replaces the donor’s contribution with his own, resulting in a child that is unmistakably his. Hmm. Now I begin to regret using the words “distasteful” and “sweet.”

Written by Allan Loeb (“21”) and based on a Jeffrey Eugenides short story called “The Baster” (ugh), it was going to be directed by Bobby and Peter Farrelly at one point, and goodness knows how they would have ratcheted up the ick factor. Instead, we get Josh Gordon and Will Speck, the duo behind the silly “Blades of Glory,” who make us squirm a bit with the biological details without overdoing it. At its heart, it’s really not that different from a regular romantic comedy. Well, except that it’s funny.

Jason Bateman and Jennifer Aniston, both sitcom veterans who have yet to achieve big-screen stardom, play New Yorkers named Wally and Kassie. Having dated several years ago, they are now best friends, Wally’s high-strung neuroticism balanced by Kassie’s easy-going calm. (To symbolize their differences, Wally has a career as an equities analyst, while Kassie does makeup for TV news.) Kassie announces that, well, she’s not getting any younger, and she really wants a baby, so it’s time to find a stranger to put one in her. Wally vocalizes his disappointment that she wouldn’t just have him be the donor, to which Kassie responds that 1) they’re best friends, so it might be weird, and 2) Wally is a pessimist and a hypochondriac, and what if those traits are inherited?

The chosen donor, Roland (Patrick Wilson), is bland and handsome, though you might have guessed that by seeing he’s played by Patrick Wilson. Here we arrive at the crucial juncture in the story: somehow, Roland’s donation must be replaced with Wally’s. Many questions are raised. How would Wally have access? Doesn’t fathering Kassie’s child without her permission make Wally an awful person? Or could he somehow do it unwittingly, absolving him from guilt? Could this be an accident somehow?

All of those questions are answered in a manner that is satisfactory, if not entirely plausible. (Let’s just say I’ve never heard of an “insemination party.”) From a story standpoint, the goal is to get past all of this fairly quickly and get to the real action, seven years later, when Kassie and her child move back to town and re-enter Wally’s life.

The kid’s name is Sebastian, played by newcomer Thomas Robinson. He has big, forlorn eyes and a Debbie Downer-like tendency to focus on things like overpopulated animal shelters and potential illnesses. Details both large and small hint that he might be Wally’s son, not Roland’s. If nothing else, Wally becomes something of a father figure to him.

And here we are with an improbable mix. The initial switcheroo premise is gross, and we see more of the, um, process than I would have thought possible in a PG-13 movie. Yet once the real story kicks in, it has a father-and-son, “About a Boy” kind of vibe that’s genuinely touching. And on top of all that, the rom-com elements of Wally and Kassie’s relationship, while formulaic, are nicely played. It would have been easy to use the outrageous “What if this crazy thing happened??” premise of Eugenides’ short story and take it no further than that. I’m impressed that “The Switch” is not content to rely on that lone gimmick.

Loeb’s screenplay is witty, especially in the early scenes, which establish Kassie and Wally’s friendship with quick, pitter-patter dialogue. Aniston and Bateman have a lively rapport that easily suggests a longstanding relationship. Also very useful is Jeff Goldblum as Wally’s coworker and friend, able to enliven any line reading with that Goldblumian delivery. And look, there’s Juliette Lewis as Kassie’s obligatory kooky friend! And li’l Thomas Robinson gives one of the most likable, believable child performances I’ve seen in a long time.

But the real winner here is Jason Bateman. Fans of TV’s “Arrested Development” have been waiting for him to find a movie that could really showcase his superhuman powers of comic timing and deadpan delivery. “The Switch” could be it. Wally is the protagonist of the story, a poignant (but funny) mess of a man who engenders sympathy despite his missteps. Bateman nails every scene he’s in, whether it calls for tenderness, sarcasm, paternal concern, or comic drunkenness, never milking a joke or mugging for the camera. He earns laughs by patiently, carefully working for them, while making it look easy. The guy’s a pro. By all rights he should be one of the most popular comic actors in the business. Let’s try to make that happen, OK?

“The Switch” becomes slightly bogged down by its desire to produce a happy ending, which is rushed at in the last 20 minutes, as if they forgot the story was going to require resolution at some point. There are inherent problems with the set-up, too, that perhaps viewers won’t be able to overlook. In all, though, this is a far better movie than it might have been, an August afterthought that can hold its head high among the other summer comedies.