When Wilfrid Brambell and Harry H Corbett, stars of the hit BBC sitcom Steptoe and Son, first met each other in 1962, it marked the beginning of one of the most successful double acts in the history of British television. By the time Corbett died in 1982, the two wished that they had never set eyes on one another. But the extraordinary story behind their bizarre relationship has never, until now, been fully told. I was brought up watching Steptoe and Son and, ever since, I've wondered what the magic ingredient was that made the show so hugely successful. Finally I decided to make a film about it. And the truth was stranger than I could have imagined.

At its peak, the programme commanded an audience of 28 million viewers. Brambell played dirty old rag-and-bone man Albert Steptoe, a festering, fly-blown Tory who lazed about the yard all day, drank distilled paraffin and couldn't care if he dropped a denture in his homemade steak and kidney pud.

Corbett played Albert's son. By day, Harold Steptoe bought and sold antique junk from a horse-drawn cart. By night, he prepared for the socialist revolution by reading books by Marx and Shaw. Harold aspired to a life beyond the gates of the family business. He was a connoisseur of fine wine and dreamed of expensive foreign holidays, but his every effort was rendered useless by the need to care for his father and the countless banana skins writers Ray Galton and Alan Simpson threw in his way.

But the two actors' real-life relationship was just as bizarre - and even more fraught - than their on-screen one. Wilfrid Brambell was gay and an alcoholic, notorious for his outrageous behaviour (on one infamous occasion he exposed himself to a woman at a party). He routinely told adoring fans who met him in the street to "fuck off". Harry H Corbett was a womaniser who hated his role in Steptoe and died a bitter and disappointed man. When Steptoe finished in 1974, Corbett loathed Brambell. Within three years, the feeling was mutual.

Brambell, fearful of fans' reactions in a less permissive time, worked hard to keep his sexuality a secret. Once or twice a year, he disappeared to Hong Kong to party with the colony's top English-language broadcaster, who many believed was his lover. On one trip he brought a young Malayan man back with him to London to be his "valet".

Brambell's drinking caused serious problems both on the show and off it. At rehearsals, he constantly forgot his lines. Once, being interviewed on television in New Zealand after he'd had one too many, he was asked by the presenter what he thought of the country. He was frank. "I hate your fucking cathedrals. I hate your fucking town. It's the lowest place I've been in all my life." Flying back the end of the tour, he urinated in the captain's cabin thinking it was the toilet, had to be restrained and was thrown off the plane at Singapore.

What were the demons that drove Brambell? Was he frustrated that he couldn't be openly gay because he knew prejudice could kill his career? Or was he distressed by the public persona of a cheeky and dirty old man, utterly at odds with his self-image as a dandy? In truth, both probably played a part, but an event earlier in his life was a factor too. In 1948, Brambell married an actress, Molly Josephine. They lived in a flat in London and took in lodgers to help pay the bills. A young and handsome student moved in and had an affair with Molly, and she became pregnant. At first, Wilfrid thought that the child was his. When he found out that it was the lodger's, he filed for divorce. Close friend Anne Pichon remembers the emotional shock to Brambell. "He was staying in my home and I would hear him wake up in the night, literally screaming, howling with pain."

Did Brambell ever share his anxieties with Corbett? It's unlikely since, away from the cameras, the two actors hardly ever socialised and seldom spoke. Production staff remember script read-throughs at which Wilfrid would be at one end of the table, Harry at the other. On the day that the show was recorded, Wilfrid would prop up the BBC bar, while Harry would sit in his dressing room, working on his lines and worrying if his well-oiled co-star would deliver. On a tour of Australia in 1976, they travelled for five months in separate cars and never once shared a dressing room.

Before Steptoe, Brambell was a professional character actor, known for playing old men in French drawing-room farces. Corbett was an intense, macho, highly political Method actor, a member of the experimental Theatre Workshop Company and feted for his performances as Richard II. While Brambell chatted rep, Corbett spoke of the collectivisation of the working class.

For Corbett, the early years of Steptoe brought him a lifestyle that was the stuff of Harold Steptoe's dreams. He bought a luxury house in St John's Wood, London, where he hosted large showbiz parties. He was a regular celebrity guest of Prime Minister Harold Wilson. He tanned in the South of France. Freddie Ross Hancock, Tony Hancock's second wife, and good a friend at the time, remembers a typical Corbett episode at the airport in Cannes when she saw one girlfriend of Harry's off at departures, only to pick a new one up at arrivals.

But in the early 1970s a rot seems to have set in Harry's mind, that was two-parts boredom with the formula of Steptoe to four-parts frustration with working with a dysfunctional drunk. Production staff remember that Corbett gave the impression it wasn't worth continuing rehearsals because, after lunch, Brambell was often too drunk. During recordings of the show, Brambell would get on Harry's nerves as, worse for wear, the old man would take an eternity to move a prop. Corbett became disenchanted by offers of work outside of Steptoe that were variations on his rag-and-bone character. Slowly, the coolness of his relationship with Brambell turned to ice.

It was in 1976, on a stage tour of Australia, that Corbett and Brambell's professional partnership finally fell apart. The Steptoe series had ended and the two actors, desperate to make some money, played any venue that would have them, in a show that turned the Steptoe theme into second-rate song-and-dance vaudeville.

On one occasion, Wilfrid didn't turn up for a show, and left Harry to entertain a 1,000-strong audience with impromptu juggling and stand-up. The tour manager found Wilfrid round the block in the front room of one of the theatre ushers, drinking Guinness. In the daytime, while Harry looked at the sights, Wilfrid either stayed in his hotel room drinking Gordons and calling the tour manager to organise a pedicure, or cruised the esplanade at Surfer's Paradise with new-found friends in a feather boa. Wilfrid told the tour manager that Harry was a pompous and stuck-up actor. Harry would just remain quiet and get on with the job, simmering inside. "Hate, that's the only word I can think of," says tour manager Kevin O'Neil.

It is said that one of the great tricks of situation comedy is to come up with a situation in which people are trapped, because real comedy only comes from tension and aggression between characters. In Steptoe, writers Ray Galton and Alan Simpson sought to highlight the generational tension between parents and children at the centre of the 60s revolution. Harold and Albert Steptoe were imprisoned in their relationship. Throughout the series, they bicker and berate one another. Whatever heights Harold aspires to, Albert brings his son tumbling down.

Ironically, after Steptoe, Corbett and Brambell appear to have found themselves in a similar situation offscreen. Typecast as a rag-and-bone man, Harry's creative ambitions bore little fruit. His professional fate was inextricably tied to the wild, secretive and unpredictable Brambell. The old man had few ambitions, other than to have a good time at his local in Pimlico and to add to his collection of antique silver.

Art mirroring life? Is this the reason why Corbett and Brambell's performance in Steptoe was so good? Tragicomedy on screen, tragicomedy off. Harold Steptoe would have loved the idea. Albert would probably have hated it.

· When Steptoe met Son, tomorrow, 9pm, C4.