Imagine a TV talkshow studio in the depths of Hell. Satan, wearing a flashy red suit, has finished singing a rousing solo directed at Jesus, consisting of just two words – “fuck you”. Christ, clad only in a loincloth, responds, in true talkshow style, by telling the Prince of Darkness to “talk to the stigmata”. This is, of course, just one of the scenes from Stewart Lee and Richard Thomas’s hit musical, Jerry Springer the Opera, that so deeply offended some of Britain’s most fundamentalist Christians. The most vociferous was Stephen Green of Christian Voice, who brought a private prosecution for blasphemy against the BBC after it broadcast the musical in 2005. The failure of this lawsuit, after the High Court came down on the side of artistic freedom, rendered Britain’s archaic blasphemy law obsolete and paved the way for its eventual abolition in 2009. Lee, an avowed atheist, was accused of deliberately setting out to offend religious sensibilities, a charge he vehemently denied. He went on the road in 2005 to defend the show and became both a hate figure for the religious right and their daily rags, and a hero for the godless.

Stewart Lee and Richard Herrgin backstage at Nine Lessons and Carols For Godless People, Bloomsbury Theatrem, Decem,ber 2009It was a strange position for a stand-up comedian to find himself in, especially one who by his own admission hates musical theatre. A veteran of the alternative comedy scene of the 1990s, Lee was one of a cadre of comics, including Baddiel and Newman, Frank Skinner, Al Murray and Harry Hill, who became some of the most recognisable and successful faces in British comedy. Lee himself parlayed success on the stand-up circuit, and writing for Steve Coogan and Chris Morris on the radio, into a TV career with collaborator Richard Herring (pictured, right, with Lee) – their BBC shows Fist of Fun and This Morning With Richard Not Judy regularly pulled in two million viewers. Yet by the end of the 1990s it had gone sour. His TV work was cancelled.

Perhaps this was because his slow delivery, biting tone and intellectual complexity were incompatible with comedy’s new laddishness. His shows had become, by his own admission, “arch, cynical, tired, fake, conceited, formulaic and flat”, and in 2001, disillusuioned and unwell, he quit stand-up. It was during this period that composer Richard Thomas asked him to collaborate on a new project based on Jerry Springer, which rapidly grew from a workshop project at an experimental South London theatre to the stage of the National Theatre in 2003 and then the West End and Broadway. It wasn’t until the BBC announced plans to broadcast the show in 2005 that Green’s blasphemy campaign began – he galvanised 47,000 to complain and a full-blown controversy erupted. BBC executives involved in commissioning it were given police protection and Lee suddenly found himself at the centre of the national debate over religious offence and the limits of free speech.

At the same time as battling the forces of religious intolerance, Lee was making his first tentative steps back to stand-up, unable, in the end, to walk away. A new one-man show, Stand-Up Comedian, debuted in 2004, featuring gags about 9/11 (which he insisted on reclaiming as the Ninth of November), while largely avoiding religious controversy. But he returned to the subject with some style in his next show, 2005’s ’90s Comedian, describing a scene that culminates in – and there is no polite way to say this – a drunken Lee vomiting into the gaping anus of Christ.

In his new book, How I Escaped My Certain Fate, Lee explains what led him to write this routine. The book is ostensibly the annotated scripts of three of his shows, Stand-Up Comedian, ’90s Comedian and 41st Best Stand-Up Ever, but it is also a painfully honest memoir of a difficult decade, a primer on the precarious economics of stand-up and a treatise on the metaphysics of jokes. Interspersed with the copiously footnoted routines is a chapter covering the Springer years and his decision to write what, at first blush, looks like a deliberately offensive routine.

“They claimed that I had set out to offend religion in Springer. Well, I hadn’t,” he told me when I caught up with him near his home in Stoke Newington, North-East London. “The subject matter was religious, but the reason why it was chosen was because the working knowledge a lot of people still have, of the mythological, storytelling aspects of Christianity, means that those stories are a really good way of making a point.” But surely they had anticipated the reaction of Christians? “No, not at all. It had been around for three or four years before the campaign started and it got good reviews in various religious papers.” Lee is convinced that the campaign against Springer wasn’t really about religion at all: “It was about homophobia and racism and weird hatred of people. Religion is just a convenient peg for people like Stephen Green to hang their hatred on.”

When he talks it is plain that the campaign took its toll on him, but you can see that it also fed his outraged comic imagination. “I was under attack from really incoherent, angry people. In Aberdeen I remember someone asked me a question and I answered it as best I could and she said, ‘It’s all just words with you, isn’t it?’ That was sort of brilliant.”

Lee has long been an open atheist, but did this change his attitude to religion? “Strangely, because we used the Bible stories in Springer, I like it more now as literature. But I am also much angrier about when religious scruples are used to block human rights or freedom of speech. A play being banned isn’t a big deal compared to homosexuals being executed, but it’s the thin end of the wedge.”

And it is this anger that he vents in the extraordinary, cathartic second half of ’90s Comedian. It is as if he said to himself, since I’ve already been accused of setting out to offend religion, let’s really go for it. Yet, as vile and gratuitous as the joke might sound, it is not only extremely funny but also strangely sweet. And this comes about in part because of another way in which religion has entered Lee’s life, in the shape of his wife Bridget Christie, a fellow stand-up comedian and a practising Roman Catholic. “She fixed that show,” Lee says, “despite the fact that it was scatologically and brutally inappropriate in its treatment of an icon that is quite dear to her. It was so useful to see it from someone else’s perspective.”

Bridget persuaded Lee that the routine would not work if Jesus was brutalised – he had to be a willing participant. It works because it is Jesus, as Jesus would, selflessly offering the distraught and drunken comedian his orifices for use as a vomit receptacle. The effect is gross, hilarious and, as the coda makes clear, a powerful statement of free speech. But just as Lee did not want to become the focus of a religious hate campaign, he doesn’t really want to be the poster-boy for religion-bating atheism either. “I don’t think that you get where you want by following the most dogmatic position,” he says. “It’s no fun preaching to the converted. You can’t just set out to offend religion, unless you’re a dick. You’ve got to have something to say.”

In his book Lee comments that atheism has become the kind of default position for contemporary comedy and, given his admiration for the avant-garde and the obscure – from the theatrical traditions of French medieval clowning to the free jazz of Evan Parker, with which he now opens his shows – he has always striven to avoid the default. This, he speculates, is what prevented him from riding the wave of late-’90s success that swept Harry Hill, Al Murray and Frank Skinner to fame and fortune. “They had football, or characters that could connect with a mass audience. I hate football and I don’t do characters, only myself and the smug-wanker version of myself. It looked superficially like we were the same, some presentable young men doing pop culture literate stuff, but we weren’t. Take Frank Skinner, you could put him in front of any audience and he could have them in stitches. That’s not true of me.”

In a way it was the success of Springer that reminded Lee where he wanted to be, back on stage alone, doing his demanding stuff that was not to everyone’s taste. In part this was because, although the musical was a hit, he actually didn’t make a lot of money from it. The huge staging costs and the distractions of legal wrangles with Christian Voice and the Daily Mail drained the life and economic viability from the show. He could also see the limitations of a large production, restricted by the need to manage a large cast and crew, agree changes and replicate itself each night. Compared to which stand-up – one person on stage with a mic – is “potentially infinite”. It cured him of the desire to be anything other than what he had always wanted to be – an “alternative stand-up”: “I was sort of cured of ambition. That was my big hit. I’ll never do anything that culturally significant again. But it didn’t have a commercial or creative future and it didn’t pay out, so it was quite good having that taken away. What it meant was you’re not hanging on any more for the big thing, you’ve got to just get on with the business of being a working artist. It was very purging.”

A key aspect of Lee’s work, which links him to the roster of avant-garde and alternative comic heroes he lionises in his book, is failure. The book is drenched in it, from his failure to emulate the success of contemporaries to his failure as a stand-up, his failure to make money out of a hit West End show, the failure of his own stomach – he developed diverticulitis, leading to serious illness and hospitalisation. But failure is also an essential part of his creative process. “Failure,” he says, “presents opportunities for subsequent victories.” He even writes “pseudo-failure” into his stand-up, shunning the cheap laugh in favour of making the audience work for a bigger payoff later. This is both a moral and a technical necessity for Lee: morally, as he is at pains to point out, the contemporary audience no longer seems to care about the difference between irony and intent, the difference between a Jimmy Carr and a Jim Davidson.

This has led to a situation where comedy originally designed to flay middle-class liberal sentiment has lost its ironic edge, and what looked oppositional has become entirely congruent with dominant thought. Lee is both scathing and compassionate about the situation some of his colleagues – Ricky Gervais, Al Murray – are in, where mass audiences miss the irony in their humour. It’s a subtle distinction, so I ask him for an example. “Jack Whitehall did a joke on TV this week, the upshot of which was that everyone in South Africa had AIDS, and was trying to nick your television. If it had been Frank Skinner you can imagine liking that joke. It would be like an idiot had said it to you in a confidential way, whereas with Jack Whitehall it was put forward as an actual opinion from a high status character that was being broadcast. It’s weirdly different.” Is this the comics’ fault? “I’m not sure to what extent it is their fault, although if it were me I would feel that I had to put a brake on it.”

This is what led him to be the only comic in the country doing routines in favour of political correctness, as he did in 2008’s 41st Best Stand-Up Ever. “I thought it’s almost the last area that’s left, trying to be sincere in the face of an increasingly glib culture. It’s not just that I thought it was the right thing to do, I also thought it was the creative thing to do.”

Stewart Leem, on stage at Nince Lesson and Carols For Godless People, December 2009Stewart Lee is probably still hated by religious fundamentalists, but elsewhere his star is rising. With the book, a new live show, Vegetable Stew, and another series of his BBC TV show Comedy Vehicle due early next year, Lee could be on the cusp of becoming a celebrity. He is already, by his own admission, “about as well-known as some of the less well-known proper famous people.”

But for a comic whose material is so dependent on the subtle ironies of failure, surely success would be the biggest failure of all? “If you become more popular you have to make the shows more difficult. You almost have to contrive hurdles and obstacles for yourself. Luckily a lot of people still hate my stuff.”

You can buy Stewart Lee 90s Comedian DVD (and Nine Lessons and Carols For Godless People DVDs featuring Stewart Lee) from the very lovely GoFasterStripe shop.

Visit Stewart Lee's website for all his tour dates

See Stewart talk about comedy and stuff