Roman Polanski knew what he was doing when he named his 1984 memoir Roman. Fortuitously, the word also means "novel" in French – the Polish film-maker was born in Paris – and his life has had the hectic fullness of a nightmare picaresque narrative. Polanski's mother died in Auschwitz; the young Roman escaped the Cracow ghetto, foraging to survive. Working in Poland and Britain, he made some of the defining films of the 1960s – Knife in the Water, Repulsion, Cul-de-sac. He and his wife, the American actress Sharon Tate, became one of that decade's golden showbusiness couples. Polanski went to Hollywood and, in 1968, made a film that still figures as one of the darkest in the horror canon, Rosemary's Baby.

Then came real-life horror – the murder of Tate, over eight months pregnant, by members of Charles Manson's "family". Polanski endured, although many wondered how, and no doubt disapproved of his continued ability to function. But function he did: in Chinatown (1974), he created one of the severest of latter-day films noirs, and arguably Los Angeles's most unforgiving cinematic take on its own history.

But in March 1977, Polanski, then aged 44, made the fateful mistake that hangs on him to this day. He had been commissioned by Vogue Hommes to take a series of photographs of adolescent girls: he wanted to show them, he says in Roman, as "sexy, pert, and thoroughly human". Polanski was introduced to a 13-year-old named Samantha Gailey, and they met to shoot some photos outdoors . They met again on 10 March for some indoor shots, and ended up at the Mulholland Drive house of Polanski's friend Jack Nicholson, who was away.

Download the new Independent Premium app Sharing the full story, not just the headlines

Champagne was drunk, though accounts vary as to how much; Gailey claimed that Polanski gave her a Quaalude, the modish prescription drug of the time; they both ended up undressed in the Jacuzzi. Sex followed, but exactly under what circumstances only the two of them know for sure. Polanski expressed it tersely in his book: "She wasn't unresponsive." Gailey's account differed: three decades later, she recalled, "It was not consensual sex by any means... It was very scary and, looking back, very creepy." Polanski was subsequently arrested and indicted on six counts: among them, perversion, sodomy and rape by use of drugs.

What happened next – rather than what happened between Polanski and Gailey – is the subject of a new documentary, Roman Polanski: Wanted and Desired, that screens next Sunday (12 October) in BBC2's Storyville strand. The film is not primarily about any perversion imputed to Polanski, but about a perversion of justice that, says its director Marina Zenovich, prevented both Gailey and Polanski the chance of a fair hearing. Using interviews and archive footage, Zenovich's film traces the legal machinations that culminated in Polanski fleeing LA on a plane to France, where he remains to this day, still risking arrest if he travels abroad.

Zenovich became intrigued by the case in 2003, when she saw Gailey – now Samantha Geimer – with her lawyer on a TV talk show. "The lawyer said that the day Polanski fled was a sad day for the American judicial system." Precisely what that means, Zenovich argues, is that "Polanski fled because the rug was pulled out from under him. He was promised something and then the judge changed his mind."

The key figure in the film, arguably, is neither Polanski nor Geimer, but Judge Laurence J Rittenband, who had presided over such celebrity cases as Elvis and Priscilla Presley's divorce. Rittenband, who died in 1993, emerges from the documentary as a bon viveur who divided his time between the courtroom and his country club, and who relished showbiz connections. And, Zenovich adds,"I find great irony in the fact that he had a girlfriend 30 years younger than him."

Hoping to preserve Geimer's anonymity, her attorney Lawrence Silver arranged for Polanski to plea-bargain, to keep the case from going to trial. Accordingly, Polanski pleaded guilty to the lowest of the counts against him, unlawful sexual intercourse. A probation report recommended against a custodial sentence, but Rittenband decreed that Polanski should have a spell undergoing "'diagnostic study" at Chino State Prison. However, he agreed to defer Polanski's custody to allow him to work on his next project, an action epic called Hurricane. At this point, Polanski made a massive tactical gaffe: on a trip to Europe, he allowed himself to be photographed, cigar in hand and surrounded by young women, at the Munich Oktoberfest. Rittenband was furious; when Polanski returned to LA, he was sent straight to Chino.

Polanski was released after 42 days of his 90-day term, but here the story gets complicated. Polanski had been led to believe by Rittenband that after Chino, his time behind bars would be over. However, the judge was overheard boasting at his country club that he would put Polanski away "for 100 years".

This was just part of Rittenband's bizarre behaviour. We learn from Zenovich's film that the judge, anxious to impress on the media that he was in control of proceedings, twice proposed to prosecuting Assistant District Attorney Roger Gunson and to Polanski's defence lawyer Douglas Dalton that they should plead their cases to him, after which he would pronounce a sentence that he had decided beforehand – in effect, amounting to a mock trial. We learn that Rittenband was inordinately influenced by publicity, and that, quite inappropriately, he solicited other people's advice on how he should act: one of them, reporter Richard Brenneman, who was startled to be asked, "What the hell do I do with Polanski?"

Daily coronavirus briefing No hype, just the advice and analysis you need Enter your email address Continue Continue Please enter an email address Email address is invalid Fill out this field Email address is invalid Email already exists. Log in to update your newsletter preferences Register with your social account or click here to log in I would like to receive morning headlines Monday - Friday plus breaking news alerts by email Update newsletter preferences

In the documentary, Geimer says of Rittenband, "He didn't care what happened to me, and he didn't care what happened to Polanski. He was orchestrating some little show ' that I didn't want to be in." Even Gunson comments – and this is the prosecutor, mark you – "I'm not surprised that [Polanski] left under those circumstances."

Zenovich stresses that her film is about the law case itself, rather than the encounter between Polanski and Geimer. "I honestly feel that no one can ever know exactly what happened that night between them," she says. "I didn't want to make a film about that – I'm not Fox News." But her carefully constructed film is startling in what it reveals about the US legal system, in which the execution of justice can apparently fall prey to the vagaries of a judge susceptible to media pressure. Rittenband was eventually removed from the Polanski case, but was heard declaring, when he stepped down from the bench in 1989, that he would get Polanski yet.

The film is also revealing about changing perceptions of Roman Polanski. He was, the film suggests, viewed in the US at the time as smacking of brimstone, cursed or even somewhat satanic himself – because of Tate's death, because of the subject of Rosemary's Baby, because of his bohemian repute as a European hedonist. He was seen by the press, says Brenneman, as a "malignant twisted dwarf with this dark vision".

The title of Zenovich's film comes from the contention of a friend of Polanski that the director is wanted in the US, but desired – respected, lionised – in Europe; as witness, footage of Polanski's induction into the lofty Académie Française. Further evidence of his mythic status on this side of the Atlantic is his appearance in the new Italian film Quiet Chaos: when the director, playing a tycoon, steps out of his limo for a last-minute cameo, you'd think a god had descended.

Polanski's revered status, and friends' testimonies to his "appetite for life" don't affect the facts of the Geimer case; besides, the case is not being tried in Zenovich's film. But does Polanski emerge from the documentary, if not lily-white, then effectively absolved? Not everyone thinks so: a reviewer at the LA Weekly felt that "Polanski comes off as a whiny, self-styled victim and a liar".

Zenovich confesses to being a fan of the director, but insists she didn't set out to present a sympathetic view. "I was very conscious of keeping my opinions out of it – my type of film-making is more to step away and let you judge." But she believes her film has given the case a degree of closure. "It wasn't my intention, but I think this film helped everyone heal a little bit. Has Polanski said that to me? No, but I would guess so."

Polanski himself appears in the documentary only in archive footage. Zenovich asked to interview him but he declined. Later, as the film was nearing completion, she tried again, and met Polanski in Paris. "He said no, [that] it would look like self-promotion."

But Polanski did watch the documentary when it screened in Cannes in May; his response was positive, Zenovich says, though "with Polanski, you never get a lot. I don't know how much of a hot-button topic it would be if he ever came out and said, 'I'm really sorry I did this.' He did to an extent, but he's reserved on that front: he's not American. When I met him I said, 'The American public needs you to apologise.' It's true – look at Hugh Grant going on The Tonight Show with Jay Leno [after being caught with prostitute Divine Brown]. It's kind of gross, but that's what this culture wants."

As far as Geimer is concerned, the case is closed: Polanski settled out of court with her in 1993. She now lives and works in Hawaii, has been married for 18 years and has three children. She finally went public in the US in 1997, appearing on TV and forgiving Polanski. She also made a statement in the LA Times in 2003, saying the film-maker should be allowed to return to the US: the longer he remained a fugitive, she said, the longer she would have to live with the story. Zenovich was impressed by Geimer when they met: "Everyone is so caught up in what happened, and she's the one it happened to, and she got past it."

Zenovich's film may seem to wrap up aspects of its subject, but only to a degree. The film ends with a caption stating that in 1997, Dalton and Gunson re-presented the case to another judge, who said that if he returned to the US, Polanski would face no more custody – as long as the proceedings were televised. Polanski declined. The Los Angeles Supreme Court has since contested Zenovich's claim, while Dalton and Gunson have issued a statement backing her. The judge concerned, Zenovich points out, is Larry Paul Fidler, who presided over the recent Phil Spector trial. "There were cameras in the courtroom for that," she notes.

Meanwhile, in July this year, on the basis of Zenovich's revelations about Rittenband inappropriately taking advice, Polanski and Dalton asked the LA District Attorney's office to review the case. This could all run and run – as could Polanski's courtroom career. Three years ago, Polanski won £50,000 in damages in a British high court over claims in Vanity Fair that he had attempted to seduce a woman in a New York restaurant, en route to Sharon Tate's funeral. He described the allegation as "the worst thing ever said about me".

In recent years, Polanski's professional repute has at last come to eclipse the layers of scandal surrounding him. His 2002 Holocaust drama The Pianist took the Palme d'Or in Cannes, then won him the Academy Award for Best Director. Meanwhile, Polanski remains in France, and has been married since 1989 to Emmanuelle Seigner, star of his thriller Frantic, with whom he has two children. When I interviewed him in Paris in 1995, he told me, "When I think about certain events of the past, I think, Christ, I should not have done this or that, and then I think – but I would not be where I am today. That's the irony of it. Turning the corner one block too late or too early changes completely your future. I find myself where I am and I'm glad, as I like my life now." It sounds like a happy ending, although the Vanity Fair trial, and Zenovich's film, suggest that some wounds have a habit of re-opening with the years.

'Roman Polanski: Wanted and Desired' is on BBC2 on 12 October. 'Quiet Chaos' is released on 24 October