Macbeth, Atonement, X-Men… James McAvoy's range is astonishing. Now he brings us Irvine Welsh's abusive, drug-fuelled cop in Filth – a film so shocking it almost didn't get released. Craig McLean talks to the star about his gruelling year

In a drab building in central Scotland, one afternoon in the armpit of winter, an actor who looks a lot like nice-guy James McAvoy is persuading a room full of blokes to – I'm paraphrasing here – Xerox their cocks.

"Come on!" he roars, all pouchy of eyes, gingery of beard and 80s of suit. A Christmas hat is jammed on his head, a bottle in his hand, as he leers malevolently in their faces. His beery challenge: where's their party spirit? Are they men or are they mice? They are, in fact, neither. They're coppers in possibly the worst police station in the world and, true to herd-like form, they duly – dully – follow his boorishly charismatic lead. Now the party can really start. Within minutes our "hero" and a secretary are using the photocopier room for altogether different purposes.

"I hated that scene!" James McAvoy is telling me, with feeling. "Is that the day you came? Aw shit…"

It is a sunny day in London, spring 2013. As we talk on the balcony of a photo studio, 16 months have passed since I watched the Glaswegian go through his paces on takes four, five, six and seven of scene 111 of his new film, Filth. "I was so gutted about that day," McAvoy continues, grumbling. "I thought we'd kicked the shit out of so much of this film, but that scene always felt a bit 'what the fuck is going on?'"

Adapted from Trainspotting author Irvine Welsh's 1998 novel, Filth is indeed a film that kicks the shit out of, well, everything: McAvoy's physical well-being (he's never looked rougher onscreen); Jamie Bell's reputation (the Billy Elliot and Tintin kid is cast as a coke-addled sidekick); and, in the end, of the cinema-going public. This is a Brit-flick that isn't afraid to get its hands dirty, even if the bestiality scene has been cut.

Filth, one of the darker books in Welsh's always-forbidding oeuvre, is the story of a copper so bent even Uri Geller would be impressed. Directed and adapted by newcomer Jon S Baird, it is a gruelling, hilarious, scabrous, Edinburgh-set picaresque about corrupt police, friend-on-friend depravity, mental illness and cross-dressing.

As un-PC PC Bruce Robertson – a drug-taking, colleague-shafting, auto-asphyxiation-loving swine – McAvoy is a sensation. He's even required to sexually threaten his actress sister Joy, four years his junior, here cast as a gang member. It's the first time the McAvoy siblings – raised on a housing estate by their grandparents after their parents split when James was seven – have acted together. "Apart," he chuckles, "from pretending I hadn't beaten her up when we were kids…"

We've not seen a British film like Filth before. And even in a busy career that's barely halted since he graduated in 2000 from the Royal Scottish Academy of Music and Drama, we've not seen the star of The Last King of Scotland, Atonement and Arthur Christmas in such a pungent role. "I don't think it pulls any punches," muses McAvoy of a film so challenging that Baird had to scrape together finance from all over the place, including Sweden and Belgium. Fully 26 producers are listed in Filth's credits, and the profusion of creative opinions led McAvoy to take a pay cut in return for his own producing role, the better to give Baird extra leverage and stay true to the film he wanted to make.

McAvoy isn't overstating the X-rated credentials of the film – which boasts an excellent supporting cast, including Eddie Marsan, Jim Broadbent, and Imogen Poots – nor the procedural challenges involved in shepherding Filth to the screen. When I talked to Danny Boyle earlier this year about his recent thriller with McAvoy, Trance, the director talked approvingly of the actor's "pugnacious character", but he also seemed to have some inside knowledge of Filth's tricky progress towards the screen. "Our editor saw it and he said James is unbelievable in it – but whether anybody will ever get to see it 'cause it's so out there…"

Boyle's worries were misplaced – Filth is being released nationally, first in Scotland, then a week later in the rest of the UK. Still, McAvoy does agree, with evident satisfaction, that Filth is "bonkers… It asks a lot of the audience, and there will be people who walk out of the cinema, I'm sure of it. And there will be people who don't understand it and get totally lost. But for those who get it, I think they'll really love it." All told, it's just the kind of role relished by a 34-year-old forcefully pushing his career in new directions.

Partners in crime: in Filth with Eddie Marsan. Photograph: Rex

As we talk in the midday sunshine, McAvoy is still processing another tough performance: his Olivier Award-nominated, 88-show portrayal of Macbeth at London's Trafalgar Studios, which closed three days previously. Five-foot-seven but broad, he had attacked the role with gusto, amplifying Shakespeare's warrior king's battle-hardened vigour and raging nightly across director James Lloyd's dystopian set.

"I'm not surprised that he's physical as Macbeth," says actor Mark Strong, who played opposite McAvoy in his other recent thriller, Welcome to the Punch. "The same was true in our film – you get the sense of an actor who is very physically capable."

Still, for all his fitness, Macbeth's lengthy run has taken its toll. "I've broken my thumb," McAvoy says, waggling a horribly swollen appendage. "I got hit by somebody's axe. I got stitches in my eye 'cause somebody hit me with their machete," he adds with something like pride. "So I was ready to finish physically, but I am kinda bereft, really. I'm just missing being Macbeth, and making people shit themselves nightly, and making people in the audience faint – which was getting really good fun! We were getting quite good at making people faint.

"Some people didn't like it," he shrugs of the grungily violent production. He insists he didn't mind the occasional walkouts during Macbeth (I saw it, and it was gruelling), nor the "couple" of bad reviews. "But for people who do like that, I wanted to be able to give a million per cent, and leave nothing behind. Leave a lot on stage; leave a bit of yourself on stage. I like other kind of work, too," he adds, "contemplative pieces, or cerebral pieces. But my favourite kind of theatre is seeing people sweat blood."

‘I am kinda bereft. I’m missing being Macbeth and making people shit themselves nightly’: James McAvoy as the Scottish king, with Claire Foy as Lady Macbeth, earlier this year. Photograph: Johan Persson

McAvoy lives in north London with his actor wife Anne-Marie Duff and their three-year-old son Brendan. What, one wonders, is he like at home during an 88-performance run of a three-hour play that has him this steamed up?

"I'm not closed off – I'm just knackered. I've done long runs before, but it wouldn't be so bad if it wasn't for the physical way that we approached the play. So I wasn't doing any DIY," he jokes, "and I wasn't playing football at the weekend any more – I couldn't, I was just too sore. I had about enough time for my kid, and a wee bit of time for my wife. And that was kind of it, man. The rest was just trying to go: 'Fuck fuck fuck fuck fuck, how am I gonna do this tonight?'"

McAvoy is certainly committed, something that's been readily apparent every time we've met. We've talked amid the bodybuilding powders cluttering the kitchen of his rented Prague flat (where he was filming comic-book adaptation Wanted with Angelina Jolie), and in a bar in Leipzig (he was shooting Tolstoy biopic The Last Station, his sole big screen work with Duff). We've had breakfast in Soho and drunk tea in his living room in his home (he was just starting Macbeth). He tends to be loquacious, but business-like – there's no smalltalk – although he has gradually revealed a little more about his private life: the odd comment about Brendan, the occasional insight into how he and Duff manage their often conflicting lives.

"We've been really lucky in that regard in the past three years – I've not had to be away much, and neither's she," he says of the woman who became his wife in 2006 after their onscreen relationship in the first two seasons of Shameless became something offscreen, too. When, recently, Duff had to film in Manchester and Ireland, on both occasions McAvoy accompanied her. When he spent two months in New York last year filming The Disappearance of Eleanor Rigby (an "adult film about grief" also starring Jessica Chastain), Duff briefly put her career on hold and came, too.

"So we've been fine," he says briskly. "It's been a fairly cool time. The first time it is going to be hard is this year. 'Cause I'm contractually obliged to do the new X-Men film." Over a five-month shoot in Canada, he's reprising his role from 2011's X-Men: First Class – the young, able-bodied and hirsute iteration of the "grown-up" X-Men films' Charles Xavier/Professor X, as portrayed by the hairless and wheelchair-bound Patrick Stewart.

James McAvoy with his wife Anne-Marie Duff, who he met on the set of Shameless. Photograph: Richard Young/Rex

"I can't make the decision to choose life over career," he continues firmly, which I know is something he's readily done before. "I have to go. And she also is doing a job that she'd already accepted by the time X-Men came around." He's referring to Duff's appearance in the National Theatre's recently ended production of Eugene O'Neill's mammoth Strange Interlude. "So it's the first time we're ever gonna have to confront it: being not a proper, together family for a sustained period, really."

Keeping it together. Staying out of the spotlight. Taking his job seriously. It's the McAvoy way. He's no A-lister gad-about: he's a serious bloke who prefers to keep all the drama out of his life and on the screen. He lives in a far-from-flashy terraced family home. He likes motorbikes and football. He's regular, likeable, malleable. According to his co-stars, he's a joy onset.

"James is really quite a gentleman," says his Filth co-star Imogen Poots, who plays a policewoman on the receiving end of Robertson's spittle-flecked misogyny. "He puts everyone at ease – it's just this beautiful gift. I don't know how many actors really have that skill, to make everybody around them so comfortable. I think that just sets the bar on a set. And he's extraordinary to watch, too. And very, very funny."

But he's also a young-looking charmer, and not an obvious choice to play the 38-year-old, bilious, anti-hero degenerate of Welsh's novel. "It was always a question of: can we get away with my youthfulness?" affirms McAvoy. "I was 32 when I made Filth, which isn't that young. But I've kinda got young features, which will hopefully disappear some time soon so I can play my age" – he frowns – "which I am starting to do more," he adds hastily.

For the team behind Filth, this was the appeal. "That was the luck of getting someone like James," says Ken Marshall, who is described as "the real producer" by McAvoy. "Because the key to this film is making sure that you have a likeable character. While it's quite a tragic story, and Bruce is quite a despicable character, what you get with someone like James is the audience going into the cinema already liking him, already feeling a degree of warmth."

Jon S Baird recalls his and Irvine Welsh's first face-to-face encounter with McAvoy in London in early 2011. "And I was thinking; 'Jeez, I'm not sure I can see James McAvoy in this…'" remembers the director. "But he walked in as a smiley guy next door – and the way Irvine describes it, within 10 seconds he turned into a grizzly cop."

"James is the engine for the film," states Welsh, "and it's one of the most amazing acting performances I've ever seen. He's pushed himself and shown a whole different range to his repertoire that he's not had the opportunity to display before in the roles he's taken. I think it's better than Robert De Niro in Taxi Driver."

Um, really?

"Yeah, he does everything De Niro does and plays this kind of anti-hero that you're on the same side of, but he goes further out than De Niro did. And he also plays it with a kind of pathos that De Niro never got close to."

McAvoy would scoff at such fantastic(al) praise. But I relay Marshall's comments – about his being likable onscreen – and he shrugs. Yes, this is a film that roughens the edges and toughens him up, "and that was an attractive thing for me".

Would he rather be a leading man or a character actor?

Upward curve: ‘I like to be the guy who’s in the most scenes and has the most lines’ Photograph: Jake Walters for the Observer

"I'd like to be character lead," is his immediate reply. "That's what I'd like to be. The kind of part I played in Atonement is a leading man, and Filth is a character lead." He thinks about this. Actually, "what I like to do is be the guy who's in the most scenes, has the most lines, and has the best part! But hopefully not have to be too straight," he says with a smile.

It is time TO GO. McAvoy has only a few more days of freedom before he flies to Montreal for the epic X-Men: Days of Future Past shoot. The superhero franchise is a rare excursion into blockbuster territory for him. Is this the film in the original series where his character goes bald? "I think I do, yeah, I'm waiting to see," he replies, hedging his bets – the star of a superhero film reveals plot spoilers at their peril.

Has he been fitted with a skullcap? "Oh fuck, mate, don't!" he winces. "I think I'd rather just go proper baldy – shave it, and wear a wig for when I don't need to be bald." It worked for Jessie J, I say. "Yeah, but she's fit," he grins. "I'm getting on a bit. I'm not gonna look good bald… But, yeah, it's gonna be good. We've got an amazing bunch of people – we've got [Michael] Fassbender back, Nick Hoult back, Jennifer Lawrence back – we all had a cracking time last time. And the old guys – I don't mean old people," he adds hastily, laughing, "I mean the people from the old movies."

Again he's "sworn to secrecy" as to how exactly the younger incarnations of the original X-Men cast interact with Patrick Stewart, Ian McKellen et al. "Ah cannae talk about it," he grins, going full Glaswegian for a minute, "but we will get to hang out. And there's going to be four Macbeths! Me, McKellen, Stuart – and Fassbender's gonna do it on film, apparently, some time at the end of this year. So I'm sure that's gonna be a right old giggle."

It's a long shoot, but presumably a lighter role for McAvoy? A lot of touching his temple and pretending to read minds… "Yeah," he nods. "It'll be a doddle, man. Compared to what I've just been doing. Be a doddle compared to Eleanor Rigby, to Trance, to Filth – the lot. I mean," he clarifies, "there is some fairly emotional and mental, draining stuff in this new one – 'cause you've kinda got to fuck Charles up a little bit. But yeah," he says with a thin smile, "you're not gonna go to the places you go to in Filth."

Filth opens in Scotland on 27 September and the rest of the UK on 4 October