SPOILERS AHEAD. DO NOT READ IF YOU HAVE NOT SEEN SHERLOCK SERIES 4 EPISODE 3 THE FINAL PROBLEM

The Sherlock season four finale contained a moving and unbearably tense scene set in Molly Hooper’s kitchen, in which Sherlock saves the pathologist’s life at the last moment.

Sherlock's psychotic sister Eurus has constructed a scenario in which Benedict Cumberbatch's character – held captive on the island prison of Sherrinford – is involved in a phone call with Molly during which he must get her to say the words "I love you" to him. Unbeknown to Molly, if Sherlock fails Eurus claims she will blow up Molly's flat.

It is a moment fraught with tension and high emotion as the character, played by Louise Brealey, struggles with her powerful feelings for the consulting detective – who clearly does not return her affections but is desperate to save her.

And perhaps appropriately for a moment in which he saves the day with seconds to spare, the scene itself was also written at the eleventh hour, Sherlock co-creator Steven Moffat has revealed.

The writer has disclosed that he and Mark Gatiss had an altogether different scene written for the moment in which Molly’s life was in jeopardy – before being pressurised by the rest of the production team to replace it. 

“There was a completely different scene there and two people liked it, and those people were me and Mark, and we kept saying 'No, it’s good' against a tidal wave of ‘We don’t like this scene’,” Moffat revealed at a preview screening of the episode.

“And on the very last day we spent writing this episode we sort of looked at each other [and said] ‘You know what? Everybody thinks this is shit except you and me. Let’s go to our office and think of something else'. So we did. And it was written in the morning and we came out and said 'That's the best scene in the episode'. That’s the value of getting really negative feedback."

While they didn't give full details of the scene they initially had in mind, Gatiss did say that it involved a “coffin and a time-lock” – suggesting that Molly may have been facing some form of grisly live burial.

And it seems that both writers were pleased about the teamwork that led to the last-minute change.

“We liked it very much,” said Moffat. “Everybody was right and we were wrong. It really puts you through the ringer and nothing happens except for a ticking clock… it’s really very powerful and that’s the way to do it.”