Jim Carrey owed Steve Carell. Big time. The funniest scene in Carrey’s otherwise middling comedy “Bruce Almighty” (set in Buffalo though not filmed here) is Carrey’s off-camera taunting of an ambitious TV news jerk played by Carell. While Carrey goes through a litany of funny faces and nutsy sounds to ruin the guy’s concentration, Carell, on-camera, not only replicates Carrey’s rubber-faced mania, he improves on it a little.

It’s a short sequence of low-comedy Nirvana – two hugely gifted comic actors (one of them, one of the most gifted performers in our movies) sparking each other and slaying the audience with glorious physical comedy. The movie was Carrey’s baby and Carell was instrumental in giving the film its stalwart moment.

You don’t forget a thing like that. Not if you’re a genuine mensch like Carrey, you don’t. He could, I suppose, have interpreted Carell’s slapstick mugging as rivalrous scene-stealing, but on that movie and at this stage in Carrey’s monolithically successful career, Carell was terrific in Carrey’s cause and he obviously knew it.

That, no doubt, is why Carrey is returning the favor by being the wildest, strangest and most dangerously unstable element in Carell’s new film “The Incredible Burt Wonderstone,” a pleasant, if largely innocuous comedy about a Las Vegas magician and overpaid and overpromoted jackass who has to be humbled completely before rejoining the human race and rising to the heights again.

Left to his own devices, Carell is funny enough, but there is always a near-tidal wave of genuine sweetness in him which is barely dammed up in his own movies and is usually ready to drown everything in mushy sentimentality and didacticism.

That’s where Carrey comes in this time. He’s the spritz of authentic craziness that gives “The Incredible Burt Wonderstone” the edge that it needs to avoid dissolving into mush.

Carell is Burt. As a boy named Wenzelstein, he was a bullied little shrimp. The big kids told him “nobody likes you, nobody will ever like you.” And then one day, he got a birthday present from Mom of a Rance Holloway magic kit. He befriended a sickly kid in the school lunchroom, who breezily explains why testosterone pills are among the many he takes by saying “my doctor says I’m dangerously close to being a girl.”

The outcast boys bond over magic and grow up to be Steve Carell and Steve Buscemi, i.e. Burt Wonderstone and Anton Marvelton, partners in an unbearably corny third-rate Vegas magic act that is, for a while, a big draw in its own theater at Bally’s. Whereupon Burt starts acting like a conceited and nasty jackass in almost every possible way – to women, his partner, his own spray-tanned self.

They’re like an intolerable Siegfried and Roy, sans animals.

But all the time they’re riding high, a new element is going around in the world of magicians – weird and extreme street magic whose leading practitioner is a self-styled master named Steve Grey, who has a cable TV show delicately named “Steve Grey, Brain Rapist.” (Yes, that’s a joke that might have been rethought.)

The public loves it.

Burt and Anton? Not so much. Their ticket sales plummet. They fight all the time and abuse female assistants. They try to do big stunts and blow them. Finally they split up.

Which leads to Burt truly bottoming out – living in a very cheap motel and doing his act in a retirement home for whoever will pay attention.

Where, yes, he is heckled by none other than Rance Holloway, now old and still played by Alan Arkin, whose career at 78 is fizzing in a delightful way. (I wish we’d seen this much of him 30 years ago when he was far more serious about what he did on the screen.)

Burt’s continuing comeuppance is secured with the help of the beauteous Olivia Wilde, playing a magician who is somehow able to forget that Burt is the biggest jerk in Vegas.

Burt’s sudden metamorphosis into a nice, sensitive Steve Carellish fellow is the biggest magic trick in the whole movie. Frankly, I have no idea how it was accomplished. It’s just that one minute he’s the biggest fool West of the Rockies and next he’s making sweet purring noises at everybody.

We’re supposed to believe that meeting up with the now-elderly Holloway and his beautiful former assistant had something to do with it, but it looks to me as if someone snipped five minutes out of the film and hoped we wouldn’t notice.

It’s all mild and pleasant enough and occasionally pretty funny. It’s Carrey’s genuinely unpredictable presence, though, that gives “Burt” what it needs and makes it seem a slightly better movie than it is, for all the solid gag making.

Still, how can you dislike a movie where a formerly smash-hit magician meets up with his boyhood idol of three decades before and asks what happened to him, only to be told by Rance (with Arkin’s exquisite comic delivery) “I quit the business. I don’t read the trades and I’m late for my coma.”

There are times when the movie, in truth, seems a little late for its coma, but not when Carrey’s around.

Make sure you stay to the very end. The funniest sequence in the film is what goes on before the closing credits.

the incredible burt wonderstone

2 and 1/2 stars

Starring: Steve Carell, Jim Carrey, Olivia Wilde, Steve Buscemi

Director: Don Scardino

Running time: 100 minutes

Rating: PG-13 for sexual content, dangerous stunts, a drug-related incident and rough language.

The Lowdown: A street magician’s rising popularity threatens a superstar Vegas magic team.