Outgoing Doctor Who boss Steven Moffat and departing Time Lord Peter Capaldi were “probably the least emotional” of crew on the set of their final episode, the showrunner has said.

Capaldi and Moffat will both depart the show after the Christmas Day special, Twice Upon A Time, with Jodie Whittaker taking over as the Doctor and Broadchurch creator Chris Chibnall becoming showrunner.

The festive episode sees the Doctor meet up with his former self, played by David Bradley, and embark on a mission alongside a First World War captain (Mark Gatiss) and assistant Bill Potts (Pearl Mackie).

The emotional episode left “everyone on set” in tears, according to Gatiss, who called it “moving and extraordinary to be a part of”.

However, Moffat said he and Capaldi put so much into making sure the Doctor’s farewell was right that all the emotions were left on the screen.

“By the time we got to that part of filming I think Peter and I were probably the least emotional on set because we’d put it all in the show,” he said.

He said writing the episode was “enough to contend with”, adding: “You can’t have the real-life drama of two old Scotsmen making their way to the door.

“Once we got into shooting it … especially when we approached filming Peter’s last moments as the Doctor which were done at the end of the shoot, we did talk more about how exactly he should meet his end.

“We were both very pleased with that final section of the script already but as we went through piece by piece we thought there were ways to improve it, so I’d be banging out new pages each night for us to discuss on set each day.

“That was so enjoyable and exciting to do – to really feel that we were getting his send-off right – that in a way it took whatever emotions we were both having about leaving and put them on screen where they belong,” he added.

Doctor Who: Twice Upon A Time airs on BBC One on Christmas Day at 5.30pm.