As most Doctor Who fans know, we’re rapidly approaching the end of Steven Moffat’s era. There’s no question his showrunning tenure has been a divisive one, but at least here in the States, it was on his watch that the show attained such immense popularity. He has scripted more stories and filled more minutes than any other writer in the show’s history. (Due to the classic series’ serialized format, though, he hasn’t written the most episodes.) You’d think he’d have run out of ideas by now, but as “Extremis” proves, that’s hardly the case. If the previous five episodes nestled you into a comfort zone of sorts, “Extremis” aims to knock you flat on your back. I’ve said it before, and I’ll say it again: Moffat’s greatest strength is his unpredictability.

First, let’s talk vault, which is perhaps the only predictable aspect of “Extremis.” Presumably, Missy (Michelle Gomez) is inside. I say presumably only because we never see the Doctor open it and view Missy on the inside, despite the chronicling of the events that led up to her imprisonment and a blind Doctor in the present whispering to Missy from outside the vault. However, this wraparound tale tells of events “a long time ago” (in the show’s timeline, seemingly some time after the events of “The Husbands of River Song”), in which Missy has been condemned to execution by an unnamed race who developed the technology to destroy a Time Lord for good. But why Missy? Why now? What has she done? These questions go unanswered, so while we’re given the answer to who’s in the vault, that answer gives way to a whole new batch of questions.

The robed figures, led by Rafando (Ivanno Jeremiah, Humans), bring the Doctor in to perform the execution. It is custom to have a member of the condemned’s species pull the lever, and as Rafando points out to the Doctor, “Your people are not easy to come by.” Nardole shows up with River’s diary in hand. The poetry of the words of his recently deceased wife affects the Doctor, and alters his attitude toward the situation before him. When it comes time to do the deed, he’s jiggered with the mechanism and weakened Missy rather than killed her. The vault that would have held her remains now becomes her prison. This is also seemingly where the partnership between the Doctor and Nardole began, though where the events of “Dr. Mysterio” fit in is unclear.

In the present, the recently blinded Doctor moans through the vault door, “They can’t know I’m blind, Missy. No one can know. Memories are so much worse in the dark.” He wears the sonic shades, which translate basic visual information to him, like who is nearby and their basic stats. He receives an email with the subject “Extremis,” and the opening credits roll. “In extremis” is a Latin phrase meaning “in the farthest reaches” or “at the point of death.”

The rest of the episode is an elaborate simulation: a test created by an alien dead-set on conquering Earth, to see what obstacles it would have to overcome in order to succeed. It stands to reason that the Doctor would be one of them, if not the obstacle. Of course, we don’t find any of that out until the end of these disturbing events, which are presented as part of the ongoing story. For recapping purposes, however, it’s best to start with the revelation. The story is told in the form of an email sent to the present-day Doctor from the shadow Doctor in the simulation. It is unclear exactly how much of what we see is also seen by the Doctor — we’re privy to numerous scenes that the sonic shades were not around to record — but he certainly appears to have gotten the gist of it all by episode’s end.

The shadow Doctor stands alone in the dark. He has no need for lighting as he is blind in the simulation as well. The lecture hall suddenly fills with people, his shades kicking into overdrive attempting to identify everyone. Cardinal Angelo (Corrado Invernizzi) is followed by none other than the Pope (Joseph Long). They plead with the Doctor. He must come to the Vatican and read an ancient manuscript entitled “Veritas.” All who have translated and read it before have committed suicide: “They read Veritas, and chose Hell.” Before going to the Vatican via TARDIS, they stop off in Bill’s apartment, and in one of the episode’s only humorous scenes, the sudden appearance of the Pope and his clergymen send Bill’s date Penny running for the door. “Extremis” has great fun cracking wise at the expense of religion.

At the Vatican, the Doctor, Bill, and Nardole are taken to the Hereticoma, the library of forbidden and heretical text, deep inside of which is the Veritas. There, a priest, Piero (Francesco Martino), secretly translated the text and emailed a copy to CERN. He then shoots himself. In order to read the text, the Doctor produces a piece of Gallifreyan tech that will allow him to see for a short time, but it’s painful to use and will cost a future self … something. Because the Doctor doesn’t want Bill to know of his condition, he sends her and Nardole away, and they find themselves embroiled in their own horrific discoveries via a portal that leads them to the Pentagon and then to CERN, where they begin discovering the truth. Everyone at the facility has gathered together to commit ritual suicide. A clock counts down the minutes, while they all get progressively hammered. Nardole spies loads of dynamite under the tables of the room. When they demand answers, the truth — the Veritas — is revealed through a simple game of number guessing. No matter how many times everyone in the room guesses, they all guess the same number, including Bill and Nardole. They run from the room back into the portal entry spot seconds before the explosion. There, the truth becomes even clearer when Nardole reaches outside of the projection, only to disappear from existence. It is an utterly chilling chain of events (the CERN sequence is the stuff of nightmares), but no more so than what the shadow Doctor encounters back in the Hereticoma.

The villain reveals itself as a being of grotesque horror — demon is the only word that leaps to mind, although the creature is credited as “Monk” in the end credits. It doesn’t want the Time Lord to read the Veritas, and an unnerving chase ensues. Eventually the Doctor reads it, and makes his way through a portal into the Oval Office (the dead president is yet another unsettling touch) where Bill finds him thanks to a trail of blood from his wounds. He knows. She knows. There is nothing left to do. She disappears from existence. The Doctor does the only thing a computer simulation can do, and that’s email another computer — in this case, the sonic shades worn by the real Doctor — and the story comes full circle.

This hour of Doctor Who is surely unsuitable for young children. Hell, it’s disturbing for adults. Everyone, aside from the shadow Doctor in his final moments, gives up. What else is there to do upon realizing you don’t actually exist? Has any other episode in the entire Doctor Who canon presented darkness and hopelessness on this scale? It is irrelevant that it wasn’t “real,” because it was real to every single person in the simulation.

Odds and Ends

• Ace bits: The Doctor’s coat in the execution scenes, Murray Gold’s soundtrack, Matt Lucas is brilliant this week, and basically all of the dialogue throughout the script.

• As I understand it, this is the first part of a three-part story line.

• I’m no papal authority, so I had to look up Pope Benedict IX, whom the episode presents as female and someone whom the Doctor had a good time with. In fact, Benedict IX was a man and quite a scandalous pope at that. I wonder why Moffat altered that history?

• Is the fact that the Doctor has the sonic that was destroyed last week a clue that this is a shadow world?

• The Master was previously executed — by the Daleks — in the TV movie.

• Moffat seems to have added to the Time Lord physiology canon: They now have three brain stems.