The Doctor is in ... for a ghost story on the BBC.

Former "Doctor Who" star Peter Capaldi (who played the 12th iteration of the famous time traveler) is set to star in "Martin’s Close," from "Doctor Who" and "Sherlock" writer Mark Gatiss.

"Martin's Close" is an adaptation of the M.R. James story, which follows the 1684 murder trial of John Martin. He has been accused of killing a young girl named Ann Clark, with whom he had a one-sided romance. During the trial, Martin seemingly acts in a guilty manner when confronted with a possible apparition of the girl.

In the end, Martin is found guilty of the crime, despite his attempt to have the case dismissed on a legal technicality, and is sentenced to death.

Capaldi will play barrister Dolben, with Wilf Scolding ("Game of Thrones") as John Martin.

The 30-minute drama follows "The Dead Room," Gatiss' Christmas project last year.

"After the delightful success of last year’s 'The Dead Room,' it’s a fantastic privilege to continue the tradition of the Christmas Ghost story on BBC Four – and what better than one of my favourite stories by the master of them all, M.R. James?” Gatiss said.