It was the moment, perhaps, when A Clockwork Orange ceased to be dangerous. In Cardiff in April 2002, halfway through the first night of her world tour, after a blast of Beethoven's Ninth, Kylie Minogue pranced on stage – in a black bowler hat and a white jumpsuit. She then launched into Spinning Around, surrounded by dancers dressed as truncheon-swinging droogs in red codpieces.

Minogue was by no means the first to borrow A Clockwork Orange's iconography over the past 40 years. In live music alone, such a list would include David Bowie, Led Zeppelin, countless punk bands, Madonna, Megadeth and Sepultura, as well as Blur, Usher and Lady Gaga, who, in her live shows last year, made her entrance to the film's theme music. And with each new appropriation, it gets that little bit harder to remember what all the fuss was about in the first place.

In this country at least, A Clockwork Orange, Stanley Kubrick's stylised sci-fi tale of a delinquent gangleader's sadistic crimes (and the state's equally sadistic rehabilitation of him), always benefited from an extra aura of mystique – for having generated moral panic on its release in 1971, and for being withdrawn from circulation by its director in 1974. Until Kubrick's death in 1999, just about the only way you could see it in Britain was on an illicit third-generation video copy, which added a frisson of danger but made for a fuzzy, muffled watch. This week, to mark its 40th anniversary, a newly restored version will be unveiled at Cannes, and released shortly after on Blu-ray. So the film's journey into mainstream respectability, and availability, is finally complete.

About time, too, says its star Malcolm McDowell. "When we made the film 40 years ago, we made it as a comedy, albeit a very black one. There was a lot of humour, but when it came out, because it was so startling and shocking, people just sat there dead silent. At the end, they didn't move out of their seats. Of course, I know it has a lot of violence and stuff, but it's more psychological than ketchup on the screen. Now audiences take it how we meant it. They really have a good time and laugh. They have caught up with it."

The making of A Clockwork Orange, including McDowell's punishing experience of working under Kubrick, is now the stuff of legend. In the second half of the movie, McDowell's character Alex receives just about every punishment that he has dished out in the first. This made for a shoot characterised by beatings, bruisings, near-drownings and extreme torture in the name of the notorious "Ludovico treatment", during which McDowell's eyes were held wide-open by clamps.

The fact that Kubrick never really knew what he was after until he found it meant that each traumatic scene had to be enacted again and again, a technique that infuriated many of his actors. "I was subjected to physical abuse," laughs McDowell. "But I understood. I thought, 'Here I am playing one of the greatest parts I'm probably ever going to play. A little pain now, a little gain later on.'"

Humour was the essence of his relationship with Kubrick. "The blacker the joke, the more he'd roll about laughing. He was always looking in every scene for 'the magic'. I'd say, 'Have we found any magic yet?' And he'd say, 'No.' And I'd say, 'Go off to the bathroom, Stan. Whenever you go to the bathroom, you always have some idea.' I think he would just pause while having a pee and go, 'Ah!' And he'd come running back and go, 'Right. Now put the camera over here.' It used to be a standing joke."

At the time, cheap, youth-oriented movies like Easy Rider were making the older generation look square, as well as turning a handsome profit. So when his beloved Napoleon project fell through, the 40-year-old Kubrick set about making his own youth movie, closer to Easy Rider's methods than those of his labour-intensive 2001: A Space Odyssey. It was mostly location shoots, a relatively small budget, and no script beyond Anthony Burgess's novel, which they would work through almost page by page on set. It was the fastest, cheapest film he would ever make.

McDowell has his revenge

Kubrick was never exactly down with the kids, though. While he was happy to film Alex and his droogs joyriding through the night, as a driver Kubrick was, says McDowell, "so careful, he was dangerous". McDowell remembers once giving him a lift home: "I had a little MGB. I gunned it, and Stanley was absolutely terrified. I was going, 'This is a fantastic car! I love this car!' Revving it up and flying around corners. The more I did it, the more terrified he was, so the more I did it, just to get my own back. He was, like, 'Never again.'"

There may have come a point at which Kubrick stopped identifying with Alex and started identifying with Mr Alexander, the intellectual whose home is invaded by Alex's gang, and whose wife is raped by Alex to the tune of Singin' in the Rain. The media storm thrown up by A Clockwork Orange certainly took Kubrick by surprise. It was released into an already-simmering debate over censorship, sex and violence, following Sam Peckinpah's Straw Dogs and Ken Russell's The Devils.

Between Mary Whitehouse, the home secretary Reginald Maudling and Christian pressure groups, the film was besieged. "He felt maligned," says Kubrick's widow, Christiane. "He felt that it was unfair to suddenly blame every crime on him. He did not feel guilty. He felt frightened. He didn't like the sudden storm. Who would?"

Jan Harlan, Kubrick's brother-in-law and his producer from A Clockwork Orange on, says: "His big mistake is that he never talked back to the press. Nonsense was written, but his attitude was, 'Don't talk to them or you'll never get rid of them.' He could have avoided all that by being a bit more accessible, but he just hated it." McDowell and Burgess found themselves defending the film on Kubrick's behalf. "We had to circle the wagons," says McDowell.

Kubrick's stance changed, though, when two police officers came to see him at his Hertfordshire home. "I'd had my head firmly in the sand," says Christiane. "But I woke up at that point. The police said this was now beyond normal, and we had to do something. We had people standing in front of our house; our children were being approached; wherever I went people would come up to me. I don't think we even knew how famous he really was at that point. The noose was closing on us, so we did get frightened." Having fought against the film's censorship, Kubrick then effectively censored it himself, quietly withdrawing it in early 1974. "Stanley felt stupid," says Christiane, "but relieved."

Kubrick's suppression of the film could be seen as a defeat at the hands of the moral brigade, but the American director, says McDowell, did not want to give up his life in England. "He was an Anglophile. He'd lived in the UK since making Lolita [in 1962], and he certainly wasn't going back to live in New York or LA." McDowell, by contrast, relocated to the US shortly after the movie, where he has been recognised on the street ever since, primarily on the strength of A Clockwork Orange.

Beyond the UK, the movie has never been out of currency, particularly in the US, and particularly among the young. Its sci-fi stylings have aged remarkably well, and its almost abstract portrayal of out-of-control youth and paternalistic society have made it something of a teenage rite of passage, the movie equivalent of The Catcher in the Rye. Remarkably, it has been a style guide for pretty much every subsequent musical genre: punk, metal, emo, hip-hop, Britpop. Minogue's homage was entitled Droogie Nights. On the big screen, meanwhile, every time you see a gang walking along in slow-motion, a speeded-up party scene, a slow pan out from a closeup of a face, a torture scene set to cheerful music, the chances are it was plundered from Kubrick's original.

'Hitler loved good music'

So is there any danger left? The movie's sex and violence looks quaint compared with today's offerings (not to mention Burgess's original book), but its power always came from more than simple explicit shock. The rapes and beatings are "presented" to us in stylised form throughout – on stages, on cinema screens, accompanied by song and dance, and in unsettling, contradictory combinations of high art and low violence. Singin' in the Rain mixes with modernist interiors and sexual violence; Beethoven plays over Nazi propaganda; we hear Rossini while a murder is committed using pop art. It's as if Kubrick is messing with the power of culture to morally "improve" society, just as he denied the film's own power to degrade it. "Hitler loved good music," he once told an interviewer, "and many top Nazis were cultured and sophisticated men, but it didn't do them, or anyone else, much good."

As with most Kubrick films, the movie still poses big questions – about power, the curtailment of civil liberties in the name of social order, personal freedom and morality. "I think it's still a perfect parable about evil," says Christiane. "Evil that's not hampered by the slightest conscience. And it seems to me that Alex lives in a microcosm of our world. His parents are revolting in their weakness and stupidity, and the police, the doctors, the church, the social worker, the intellectual victims – all the people that surround him are really western society as we are now. The youth are opting out of politics. They're just watching vampire movies. And the rest of us are like Alex's parents, whingeing and whimpering."

Kubrick once said: "One of the conclusions of the film is that there are limits to which society should go in maintaining law and order. Society should not do the wrong thing for the right reason, even though it frequently does the right thing for the wrong reason."

When it came to the future of humanity, Kubrick was never much of an optimist. But then again, he didn't live to see Kylie Minogue play Cardiff.

• A Clockwork Orange screens on 19 May at the Cannes film festival. The Clockwork Orange 40th Anniversary Edition will be released on Blu-ray, as part of the Stanley Kubrick: Limited Edition Collection, and on download through iTunes, on 23 May.