How did Sherlock Holmes survive that death plunge? If, indeed, he did. Perhaps the falling body was Moriarty in a Sherlock mask? Or maybe pathologist Molly supplied a corpse to throw from the roof? Who or what lies in the grave over which Martin Freeman's Dr Watson delivered the lovely soliloquy that made around 7.9 million Britons' stiff upper lips tremble on Sunday night?

Steven Moffat eyes me guardedly from his living room sofa at his home near London's Kew Gardens. Why don't you just tell me how Sherlock survived, then you can go back to your study to write some more Doctor Who? "Christ, no!" says Moffat, grinning. A-ha! So that implies Sherlock has survived. (Not such a brilliant deduction: it's hard to imagine a third series without the hero.)

"There is a clue everybody's missed," he says tantalisingly. "So many people theorising about Sherlock's death online – and they missed it! We've worked out how Sherlock survives, and actually shot part of what really happened. It all makes sense." In this, he argues, he and co-writer Mark Gatiss have gone one better than Doyle. "He cheated outrageously. He has Watson deduce that Holmes fell off a waterfall. But there was no body. And it only means one thing in a detective show when there's no body." That the victim survived. So you set yourself the test of killing off Sherlock, putting his corpse in plain view and then bringing him back from the dead to watch his own funeral? "Yes. We had to have Holmes dying in Watson's arms – and get away with that, which we have." But how? Moffat sips his tea silently.

Sherlock will be back for a third series of three 90-minute episodes, hopefully before the year is out, he says. Only then will we know how Moffat, the 50-year-old Scot who masterminds two of the BBC's most successful franchises (he is co-creator and an executive producer on Sherlock as well as lead writer and executive producer on Doctor Who), brought Holmes back from the dead. "My problem is that the audience is more fiction-literate than ever. In Shakespeare's day, you probably expected to see a play once or twice in your life; today you experience four or five different kinds of fiction every day. So staying ahead of the audience is impossible."

Moffat believes the popularity of the two shows suggests reports of dumb Britain are exaggerated. "They are very clever shows, but they also fetishise cleverness. Cleverness is the superpower. So I get irritated when people say on Twitter: 'It's too complicated. I'm not following it.' Well, you could try putting your phone down and watching it."

But surely he's just writing shows for kids and TV-infantilised adults? How can these be more intellectually demanding than adult dramas? "Honestly? I think we beat them hands down. Anything can be addressed to a child audience – you just have to write it better. The restriction with Doctor Who is that you have to get on with it because it's an adventure story. You can discuss anything. We've had a suicide in it. You just have to do it clearly and honestly and with enough integrity that children will watch it and understand it, and parents will be happy that they do so."

Moffat suspects Sherlock has overwhelmingly the same audience as Doctor Who. "Sherlock is Doctor Who but an hour later in the TV schedules. Not two hours later, one hour."

Doesn't Moffat want to write grown-up stuff for two hours later? "Not really. Writing for adults often means just increasing the swearing – but find an alternative to swearing and you've probably got a better line." He says he did write grown-up stuff – Joking Apart in the 90s and Coupling in the 00s, sitcoms that riffed on his own sexual history. "You could say they were adult. Or maybe they were more childish than what I'm writing now."

Sherlock originated when Moffat and Gatiss, who were working in Cardiff on Doctor Who, discovered a shared fondness for Doyle's detective on train journeys back to London. Their idea was to free Holmes from his heritage-industry prison. He would lose his deerstalker and tweeds, but gain a smartphone and nicotine patches. He wouldn't say: "Elementary, my dear Watson." He would be younger, and technologically cutting-edge – just as Doyle had written him.

"We wanted to bring him out of the faux-Victorian fog and see him for what he is. Sherlock Holmes is really that posh freak from a wealthy family, that scary boffin crime-solver who lives in your town. Then Watson the ex-soldier, invalided out of the war in Afghanistan, coming home a bit bored because he'd rather be back at the front. So solving crimes with a psychopath excites him.

But how did Moffat and Gatiss solve the most vexing mystery, Sherlock's sex life? "There's no indication in the original stories that he was asexual or gay. He actually says he declines the attention of women because he doesn't want the distraction. What does that tell you about him? Straightforward deduction. He wouldn't be living with a man if he thought men were interesting."

Moffat is not saying that Sherlock, like Austin Powers, misplaced his mojo. "It's the choice of a monk, not the choice of an asexual. If he was asexual, there would be no tension in that, no fun in that – it's someone who abstains who's interesting. There's no guarantee that he'll stay that way in the end – maybe he marries Mrs Hudson. I don't know!"

In the latest series' first episode, Holmes was sexually discombobulated by a lesbian dominatrix who strips off in order to arouse Sherlock's sexuality from its dogmatic slumbers. I couldn't find any of this in Doyle's story A Scandal in Bohemia, from which the episode was adapted. Indeed, Moffat and Gatiss's treatment drove one critic, Jane Clare Jones writing in the Guardian, to suggest they had created a misogynistic throwback. In the original story, Irene Adler is an adventuress who outwits Holmes; in Sherlock, as Jones put it: "She's become a high-class dominatrix saved only from certain death by the dramatic intervention of our hero." She added: "While Doyle's original is hardly an exemplar of gender evolution, you've got to worry when a woman comes off worse in 2012 than in 1891."

Moffat, unsurprisingly, doesn't agree. "In the original, Irene Adler's victory over Sherlock Holmes was to move house and run away with her husband. That's not a feminist victory." He says he found Jones's argument "deeply offensive". "Everyone else gets it that Irene wins. When Sherlock turns up to save her at the end it's like Eliza Dolittle coming back to Henry Higgins in My Fair Lady: 'OK, I like you, now let me hack up these terrorists with a big sword.'

"You could only draw conclusions about my personal sexual politics if you proceed from the assumption that I was presenting the characters as the way it is and the way it ought to be. But both are clearly defined as deranged – it's love among the mad. He's a psychopath, so is she. She's prepared to throw him to the dogs until he works out the code, he's prepared to let her nearly get executed. They're not really going to buy a house and a Volvo together. I'm not saying this is how people should date!"

It's not the first time Moffat has been accused of sexism in his writing. He wrote a storyline recently about Doctor Who's mother. "I was called a misogynist because I was reducing women to mothers. 'Reducing women to mothers' – now there is possibly the most anti-women statement I've heard."

Jones also charged that during his stewardship of Doctor Who (he took over as head writer from Russell T Davies in 2008) Moffat plucked women characters "from a box marked 'tired old tropes' (drip/scold/temptress/earth mother to name but a few), and his consequent failure to sketch a compelling central dynamic between the lead and his companion has seriously affected the show's dramatic power."

Moffat balks at this. "River Song? Amy Pond [two leading Doctor Who women characters he created]? Hardly weak women. It's the exact opposite. You could accuse me of having a fetish for powerful, sexy women who like cheating people. That would be fair."

Moffat strives to ignore detractors. "I try not to go online much. They're always gunning for me." When he made Moriarty Irish, he was charged with betraying Doyle. But Moffat and Gatiss feel free to take liberties. When actor and playwright William Gillette wrote the first stage adaptation, he cabled Doyle, "Can I marry Holmes?" Doyle replied "You may marry him, or murder, or do what you like with him." But, Moffat says, they are true to the original's spirit. "Our own fanboyness about Sherlock Holmes means that there are absolute limits to what we do. Ours is an authentic version of Sherlock Holmes."

Moffat was born in Paisley, near Glasgow in 1961. After an MA in English, he became a secondary school English teacher in Greenock. His TV break came in the late 80s, thanks to Harry Secombe. The former Goon visited Thorn Primary School in Johnstone, Renfrewshire, to film his religious show, Highway. Moffat's father, Bill, the school's headmaster, allowed the show's producers to film there on the condition that they read his son's script for a TV series about a school newspaper. This became ITV's Press Gang. During its six-year run, Moffat's first wife left him for another man. He plundered that break-up for his next project, the BBC sitcom Joking Apart, about a sitcom writer and the rise and fall of his relationship. In later sitcoms Chalk (set in a school) and Coupling (which satirised male commitment phobia), he mined his own biography again.

"I write the kind of stuff I'd like to watch," he says. Ever since he fulfilled a childhood dream in 2004 and was hired to write for Doctor Who, that stuff has been, he says, "action, mystery, suspense, adventure – all those things, opposed to a deep analysis of the failures of the human heart that I could never possibly write." Why not? "Who wants to read the angst-ridden ravings of a middle-class successful writer who has had his two dream jobs – writing Doctor Who and Sherlock?"

When Moffat took over from Davies as Doctor Who's head writer, he was in Hollywood, having been contracted to write three Tintin films for Steven Spielberg. He walked out on Spielberg – what a thing to have on his CV! "I felt really guilty. Far from swaggering out of the building saying, 'I don't care about your damn movie', I felt haunted with guilt because I was the villain. I'm glad they used some of my script in the first film. Steven was lovely about it. He could have sued me."

Isn't choosing British TV over Hollywood nuts, career-wise? "Not really. I think TV is pushing ahead. It used to be we make TV on video and they remake it on 35mm. We all now work in high-def, we all have the same cameras. You can get things made the same year you think of it, rather than 12 years later. We can make three Sherlock films in the time it takes Hollywood to have lunch."

Time for one last question. It's the cyclist who knocked Watson over as "Holmes" lay crushed on the pavement who holds the key to the mystery, isn't it? Or Mycroft, Sherlock's estranged brother? Moffat shakes his head with a grin. He's enjoying this. And enjoying more, no doubt, getting away with Sherlock's murder.