Douglas Adams’s celebrated Doctor Who script City of Death, written over the course of a weekend after the producer, in Adams’s words, “took me back to his place, locked me in his study and hosed me down with whisky and black coffee for a few days”, is being turned into a novel by the author James Goss.

Featuring Tom Baker as the Time Lord, City of Death aired in 1979, and remains one of Doctor Who’s most popular serials, watched by over 16 million viewers when it was first broadcast. It finds the Doctor on holiday in Paris with Romana – played by Lalla Ward – and embroiled in the alien schemes of Count Scarlioni. Splintered into multiple aspects when his ship exploded over primeval Earth, the villainous count has been attempting to guide the planet towards inventing time travel ever since, so that he will be able to go back, and save his ship.

The final stages of his evil design are due to be financed by selling copies of the Mona Lisa which the villain forced Leonardo da Vinci to paint. But the Doctor realises the count has to be stopped, because the explosion of the Jagaroth ship was the spark for life on Earth.

The script was produced at breakneck speed and represents a “hair-whitening display of Adams’s ingenuity”, according to the writer’s biographer, Jem Roberts. Adams was working as script editor on the 17th series of Doctor Who when it emerged one Friday that there was no script for a four-episode shoot due to begin the following Monday.

Adams was drafted in by the producer to work on a storyline left unfinished by one of the show’s writers, David Fisher, due to family problems. According to Roberts, Adams recalled how the producer “took me back to his place, locked me in his study and hosed me down with whisky and black coffee for a few days, and there was the script”.

Now Goss, who has written two Doctor Who novels and produced a BBC radio adaptation of Shada, an unfinished Adams Doctor Who story published as a book in 2012, is turning the work into a novel, out in May.

“It’s a book Douglas Adams was supposed to write,” he said. “In the 80s, they wrote to him, and asked if he would like to write [his scripts] as novels - they even said they’d pay double. But he thanked them politely, and declined, and used his ideas in other books.”

Goss admitted to “slight performance anxiety” when taking on the work of the late, much-loved writer. “I knew people would be looking and saying: ‘Well, it’s not going to be as good as what he’d have written’ ... But in a way it was great, because I knew that every decision I’d make would be wrong,” he said. “When you’re essentially ghost-writing, and for someone as good as Douglas Adams, you know readers will say: ‘That’s not how Adams would have done it.’ It took a lot of pressure off.”

Douglas Adams in 1987. Photograph: Chris Barham/Daily Mail/Rex

According to Goss, Adams’s enthusiasm waned markedly in the final episode of the four-part series. “It just basically says: ‘People running around in Paris’, and writing that is not as exciting as doing it,” he said.

But the rapid construction allows for much greater freedom in filling in the back story. “Because City of Death was so hurriedly sketched out, we don’t know who many of these characters really are.”

He pointed to Count Scarlioni, who resembles a squid, but has a wife who seems to have never noticed his true appearance. “She’s quite incurious about it. But with modern eyes, we wonder did he never take his clothes off and reveal the horrible secrets beneath?” he said. “It’s one of those things Doctor Who fans will worry about, late at night – and rightly so.”

Goss has thoroughly enjoyed digging into the mysteries left behind by Adams, whom he met after helping to adapt Adams’s novel Dirk Gently’s Holistic Detective Agency for the stage.

“He came to see it, and he was incredibly generous with his time,” said Goss. “He would say: ‘Why don’t I take the entire cast out for a meal?’ He was very pleased with the play we’d done. You could tell – he was basically a giant, and when we seated him in the Oxford Playhouse, we’d be able to see him there, laughing at his own jokes. It was quite a sight to see.”

• James Goss’s City of Death will be published on 21 May by BBC Books

