Now here’s an unlikely premise for a Hollywood movie: Jim Carrey and Ewan McGregor meet in prison and fall madly in love. After they’re released from jail (through a series of subterfuges too elaborate to detail here), the pair cut a swath through the American South as a team of horny, opportunistic, unrepentant con artists. The only thing more unlikely than such a movie getting made in the first place is the idea that it would find distribution, and I Love You, Phillip Morris (Roadside Attractions) almost didn’t—it sat on a shelf while distributors puzzled over how to mass market a gay romance so blithely unconcerned with earnest uplift. Phillip Morris isn’t a perfect movie by any means, but it’s irresistibly self-assured in its weirdness.

The directorial debut of Glenn Ficarra and John Requa (the comedy-writing team responsible for Bad Santa), I Love You, Phillip Morris is based on the true story of Steven Russell. As the movie begins, Steven (played by Jim Carrey) is a churchgoing cop in Texas married to a nice Christian woman (played, delightfully, by Leslie Mann, who deserves a movie of her own already). When he’s nearly killed in an auto accident, Steven abruptly decides to stop living a lie: “I’m a faggot!” he yells exultantly to the EMS workers as they carry him to the ambulance.

But after leaving his wife and children to hook up with a boyfriend in Key West, Steven realizes to his consternation that “Being gay is really expensive.” So he embarks on a series of freelance swindles, eventually landing in prison for insurance fraud. When he meets the gentle Philip (Ewan McGregor) in the prison library, it’s love at first sight, and Steven employs his preternatural gift for deception to get the two of them assigned as cellmates and, eventually, to spring his boyfriend from jail.

Jim Carrey has struggled in midlife to find a place for his outsized, dominating performance style, sometimes tamping it down for straight dramatic roles like Eternal Sunshine of the Spotless Mind, sometimes hiding behind animated avatars as a voice actor in A Christmas Carol and Horton Hears a Who. Carrey’s performance here is broad, clownlike, and, in the sex scenes especially, almost deliberately grotesque. Yet he’s also vulnerable and tender. Ewan McGregor brings a screwball sweetness to his role as the blond, Southern nancy boy who’s both bedazzled and shocked by his boyfriend’s criminal audacity.

Though the movie is light on story, with an episodic structure that sometimes drags, I Love You, Phillip Morris is something close to brilliant in its mastery of tone. Like Bad Santa, it’s a black comedy with a caramel center. The movie goes to some really bleak places—I can’t tell you how bleak without spoiling a major twist—and shows its characters in some very unflattering lights, without ever abandoning its basic faith in the redemptive power of love. What saves that faith from being cloying is how the Steven/Phillip romance comes mixed with a heaping helping of sex—when he looks for shapes in the clouds, Steven can’t help but spot a proudly erect phallus every time.

In the end, I Love You, Phillip Morris is neither a light romantic comedy nor a pious drama of oppression. It’s a passionate, amoral caper, a story of outlaw love on the run in the tradition of Breathless or True Romance. Without making any big proclamations, I Love You, Phillip Morris neatly subverts our every expectation of what a “gay movie” should be.

Like Slate on Facebook. Follow us on Twitter.