Robert Banks Stewart played a pivotal role in casting Catherine Zeta-Jones, left, alongside Pam Ferris and David Jason in The Darling Buds of May.
Photograph: ITV/Rex Shutterstock

Robert Banks Stewart, who has died at the age of 84, was a writer and producer whose knack for casting and determination to break the mould made two of television’s most enduring detective series, Shoestring and Bergerac, big ratings winners for the BBC.

Knowing that the corporation was, in 1979, looking for a new crime show, Stewart decided to jettison the idea of traditional cops-and-robbers drama, instead conceiving – with the playwright Richard Harris – a series about a private eye, Eddie Shoestring, who works for a local radio station. With its Bristol setting (chosen by Stewart to be a welcome change from the London suburbs hitherto ubiquitous to such dramas), distinctive score by George Fenton, and breakout performance from the then little-known Trevor Eve, Shoestring became a ratings hit. It ran for two series and was nominated for a Bafta.

When Eve elected not to return for a third series, Stewart followed the same formula in creating its replacement – an eye-catching location, Fenton’s music and the casting of the right actor for the part rather than a “name”. Bergerac (1981-91) featured John Nettles as a police officer attached to Jersey’s Bureau des Etrangers (a fictional department overseeing non-residents). Jim Bergerac was recovering from injury, alcoholism and a messy divorce, and proved popular with viewers.

Robert Banks Stewart wrote two of the most highly regarded Doctor Who adventures

Robert Stewart was born in Edinburgh. His father, also Robert, was a master printer and performed as a pierrot clown in end-of-the-pier shows. His mother Agnes’s maiden name was Banks, and Robert adopted this to distinguish himself from other similarly named writers as his television career took off. He started writing at his primary school, Moray House in Edinburgh, and after winning a Burns essay prize and contributing stories to local newspapers he left school at 15 to become an office boy at the Edinburgh Evening Dispatch. National Service with Field Marshal Montgomery’s peacetime staff intervened (he subsequently gained a commission), following which he joined the Scotsman before returning to the Evening Dispatch as news editor. By this time he had written several plays and enjoyed a stint as a radio commentator.

He eventually left Scotland for a post as foreign corespondent on Illustrated magazine. When this folded he joined the Rank Organisation, providing rewrites on some of its Pinewood films, and producing scripts for both its Edgar Wallace Mysteries B-pictures and its television series Interpol Calling (1959-60). Thereafter he wrote for the Patrick McGoohan spy series Danger Man (1960-61) and became a prolific writer for television.

Over the years he contributed scripts to enduring series such as Dr Finlay’s Casebook (1964-65), The Avengers with Diana Rigg and Patrick Macnee (1965-66), Adam Adamant Lives starring Gerald Harper (1966), Callan (1967-69), Public Eye (1968), Special Branch (1969), Jason King (1972), Arthur of the Britons (1973), The Sweeney (1975) with John Thaw and Dennis Waterman, The Legend of Robin Hood (1975), and Charles Endell, Esq (1980) starring Iain Cuthbertson.

Stewart also wrote two of Doctor Who’s most highly regarded adventures. He pitted Tom Baker’s incarnation of the Time Lord against the Loch Ness monster in Terror of the Zygons (1975), for which he created a popular race of aliens who returned to the programme to fight Peter Capaldi last year. The Seeds of Doom (1976) was a terrifying story in which the alien Krynoid makes all vegetation lethal to mankind. Science fiction had featured early in Stewart’s career: he devised the series Undermind (1965), in which brainwashed humans are manipulated by a sinister alien force.

Robert Banks Stewart chose a distinctive location, Jersey, and the right actor, John Nettles, to make a success of Bergerac (1981). Photograph: Rex Features

He script-edited episodes of Armchair Theatre (1966-67), Van der Valk (1973), Rooms (1977) and Armchair Thriller (1978). He then became a producer and was responsible for the first series of Lovejoy (1986), developed for television by Ian La Frenais from Jonathan Gash’s books and starring Ian McShane as the charming rogue antiques dealer. Other series he took charge of included Call Me Mister, with the Australian import Steve Bisley as a fish-out-of-water private detective (1986), Hannay (1988), starring Robert Powell in a spin-off from The 39 Steps, and Frank Stubbs (1993), featuring Timothy Spall as a down-at-heel show business promoter.

In 1991 he produced and adapted episodes of the first series of the television version of HE Bates’s Darling Buds of May for Yorkshire Television. Another ratings hit, it starred David Jason, Pam Ferris and, crucially, Catherine Zeta Jones. Stewart played a pivotal role in her casting – another future star who got an early break thanks to his eye for talent and preparedness to give newcomers a chance. He followed this by creating the short-lived Moon and Son (1992) and undertaking more Bates script adaptations, including My Uncle Silas (starring Albert Finney, 2001-03).

Latterly he felt that ageism denied him further television opportunities. His first novel, The Hurricane’s Tale, was published when he was 81 and his memoirs of working in television, To Put You in the Picture, told with his trademark wit and self-effacement, came out last year.

Both of his marriages ended in divorce. He is survived by a daughter from the first and three sons from the second.

• Roberts Banks Stewart, writer and producer, born 16 July 1931; died 14 January 2016