Sherlock and John are contacted by Henry Knight (Russell Tovey), a man traumatised by the death of his father by a monstrous hound on Dartmoor years before. Investigating Dewer's Hollow, a local spot where the beast was allegedly seen, as well as the nearby Ministry of Defence testing site Baskerville, Sherlock and John uncover a conspiracy wherein one of the Baskerville scientists, Dr. Frankland (Clive Mantle), is continuing the work of H.O.U.N.D., an aborted project to create a hallucinogenic gas for military use. Sherlock and John discover that the legendary hound is an ordinary dog used for publicity that the hallucinogenic gas makes appear as a demonic monster. The "hound" that killed Henry's father was actually Frankland wearing a red-lensed gas mask and a T-shirt bearing the logo of the H.O.U.N.D. group. Confronting both the dog and Frankland at Dewer's Hollow, John and Lestrade shoot the dog. Frankland attempts to flee, but dies when he runs into a minefield. In the final scene, Mycroft releases a confined Jim Moriarty.
Moriarty launches a simultaneous heist on the Tower of London, Bank of England, and Pentonville Prison, crimes for which he allows himself to be captured and put on trial. He secures not-guilty by intimidating the jury and visits Sherlock, explaining he still intends to "burn" him, taunting him with a "final problem" for him to solve. He also tries to destroy Sherlock's reputation. The two meet on the roof of a hospital, where Moriarty explains that assassins will kill John, Mrs. Hudson, and Lestrade if Sherlock does not commit suicide; he wants Sherlock to do this to cement his story after explaining that his "god code" was a myth. Moriarty kills himself to force Sherlock to do the same. Sherlock calls John, confesses to being a fraud, states his final "goodbye" and then steps off the roof
Two years after his reported Reichenbach Fall demise, Sherlock, who has been cleared of all fraud charges against him, returns with Mycroft's help to a London under threat of terrorist attack. He tries to convince John—who has moved on and now has a girlfriend, Mary Morstan (Amanda Abbington)—to help; however, John is angry that Sherlock did not tell him he was alive. Instead, Sherlock enlists Molly to assist him, but when John is kidnapped by unknown assailants and is rescued by Sherlock and Mary, John returns to help find the terrorists and an underground plot to blow up the Houses of Parliament during an all-night sitting on Guy Fawkes Night.
Stolen letters lead Sherlock into conflict with Charles Augustus Magnussen, "the Napoleon of blackmail" who knows the personal weakness of every person of importance in the Western world. During the investigation Sherlock is shot and nearly killed by Mary, who is being blackmailed by Magnussen. After waking up from near-death, Sherlock escapes the hospital and lures Mary to an abandoned building, where he tricks her into revealing her false identity and attempted murder while John is listening nearby. Months later, Sherlock drugs everyone at the Holmes family Christmas party and steals Mycroft's laptop full of state secrets, and he and John take the laptop to Magnussen to trade for all of the files on 'Mary Morstan'. It is revealed that Magnussen keeps no files; it is all in his near-perfect "mind palace". To protect John, Mary, and their forthcoming child, Holmes kills Magnussen in front of Mycroft and several other witnesses, and as a result is sent off on a suicidal assignment overseas. However, he is brought back almost immediately because of a video being broadcast all over England with Jim Moriarty's face asking "Did you miss me?"
Sherlock and Watson – who had been shot with a tranquilizer by Eurus – trick Mycroft into acknowledging her existence. Eurus steps up her attacks on Sherlock, culminating in the bombing of his Baker Street apartment. Sherlock, Watson and Mycroft venture forth to Sherrinford, a maximum-security psychiatric facility where Eurus is housed. Although Mycroft is skeptical at the suggestion that she has escaped, the trio discover that Eurus has compromised the staff and controls the entire Sherrinford asylum. She subjects the trio to a series of ordeals, testing their morals by forcing them to choose which of her victims live and die and ultimately forcing Sherlock to confront the memory of "Redbeard", a childhood friend whose death set in motion events that saw Eurus incarcerated. Realising that she will continue to test him until someone he cares for dies, Sherlock tries to connect with her on an emotional level, offering her the love and relationship with a brother that she never had, and Eurus stands down. Sherlock and Watson return to the Baker Street apartment, where they find another message from Mary imploring them to stay together. A time lapse montage shows them rebuilding the Baker Street flat to its original lived-in form before meeting a series of unusual clients.