A darkly comic caper movie that’s also a frenzied gay romance, “I Love You Phillip Morris” had its release delayed by distribution problems but still suffered far fewer vicissitudes than its real-life characters, who were in and out of jail repeatedly. It now appears as a pleasant surprise—not perfect, to be sure, but distinctive, and hardly the disaster its time on the shelf might suggest.

It also represents a risky enterprise for its stars. Jim Carrey returns to his early manic roots, but with a decidedly spiky edge, to play Steven Russell. He’s introduced as a married man with abandonment issues (his biological mother turned him over for adoption) who becomes a cop and vows to live a good life. But he himself leaves his wife and kids when, after tracking down his real mother and being rebuffed by her, he has a car accident and decides to stop trying to be something he’s not. Announcing that he’s gay, he departs his family and is soon living the high life with a loving partner.

Unfortunately, the high life proves expensive, and to make ends meet he engages in checking scams and credit-card fraud that earn him a stint in prison. There he meets sweet, sensitive Phillip Morris (Ewan McGregor), a gentle soul with a Southern drawl whom he immediately falls head over heels for. When Morris is transferred to another facility, Russell undertakes the first of numerous flamboyant jailbreaks, the most amazing of which involves an intricate scheme to convince the authorities that he’s dying of AIDS.

During his time of the outside Russell not only poses as a lawyer to secure his lover’s release but cajoles his way into a position as the chief financial officer of a big firm—whose assets he then clandestinely employs in a complicated investment scheme that brings in enough profits for him and Phillip to live in splendor–until they’re caught again, of course. (It should come as no surprise that the real Russell is now kept in a maximum-security cell in Texas that keeps him in solitary 23 hours a day.)

In adapting this stranger-than-fiction tale for the screen, Glenn Ficarra and John Requa, who pushed the boundaries of good taste way over the edge in “Bad Santa,” pull no punches, painting the portrait of this con man extraordinaire and his reluctant co-conspirator in broad, garish strokes. And Carrey gives exuberant free rein to his wild side, while adding to it a sharp streak that he hasn’t really tapped since “The Cable Guy.” The result didn’t much please his fans back in 1996, and may not this time around either; but it’s a courageous performance that mostly works. McGregor complements him beautifully with a sly, understated turn that meshes surprisingly well with his co-star’s broadness. The picture is basically a two-character piece, in which nobody else is much more than a walk-on, but the supporting cast has been chosen with care and add some hilarious moments.

The style of “Phillip Morris” is of a piece with the story—extravagant and oversized, despite the picture’s relatively small scale. Xavier Perez-Grobet’s cinematography goes in for rich, neon colors and Nick Urata’s score for big gestures, and the production design (Hugo Luczyc-Wyhowski), art direction (Helen Harwell) and costumes (David C. Robinson) all follow suit. The result is a bright, cheery package for a tale that has some very dark undertones. The result won’t appeal to all tastes, of course, but if you give it a chance, you might find that it’s to yours.