There have been a strange series of deaths, supposed by Detective Inspector Lestrade to be "serial suicides." Sherlock looks at the latest crime scene, which is of a woman wearing pink. Sherlock deduces that the woman is a serial adulterer with an unhappy marriage. Unlike other victims, she left a note, clawing "Rache" into the floor. Sherlock ignores the suggestion of the forensic expert, Anderson, that it is the German word for revenge and settles on "Rachel", deeming that the victim died before finishing the scrawl. Sherlock finds splashes of mud on the woman's leg, thrown up by the wheel of a suitcase, and deduces that she is from out of town. The police found no suitcase on the premises, but Sherlock searches for it, later finding it in a nearby skip.
Meanwhile, John receives a call from a public phone and is taken to an empty warehouse. There, he meets a man who claims to be Sherlock's "arch-enemy". The man offers money in return for information about Sherlock's activities, but John refuses. When John returns to 221B, Sherlock asks him to send a text message to the phone of the fourth victim. At a local restaurant, Sherlock notices a cab and gives chase, using his extensive knowledge of London's streets and alleys to outpace it on foot. However, when he and John catch up with the cab, they find that the passenger is a newly arrived American: a perfect alibi.
Suspecting that Sherlock had withheld evidence, Scotland Yard executes a drug bust on his apartment so that they can search it. Sherlock presumes that "Rachel" was the victim's e-mail address password and that the victim had planted her phone on the killer so that he could be traced by GPS. At the same time that John finds that the signal is coming from 221B, Mrs. Hudson tells Sherlock that there is a taxi waiting for him downstairs. Sherlock leaves the apartment and enters the cab. The cabbie confesses, but proclaims that he doesn't kill; instead, he speaks to his victims and they kill themselves. He challenges Sherlock to solve his puzzle. They arrive at a school building, and the cabbie pulls out a gun and two bottles. He claims that one contains a harmless pill and the other a poisonous pill. Sherlock realises that the cabbie is dying, and calls his bluff on the gun, which is actually a novelty cigarette lighter. He walks off, but the cabbie challenges him again to choose a pill and see if he can solve the puzzle.
Meanwhile, John has traced the GPS signal from the victim's phone and followed Sherlock. Through a window in the adjacent building, John sees Sherlock about to take one of the pills, and shoots the cabbie. Sherlock questions the dying cabbie, first about whether he got the pill game right, and then about his "fan" that the cabbie had mentioned. Finally, the cabbie reveals a name: "Moriarty".
Outside, Scotland Yard has surrounded the perimeter. Sherlock starts to make some deductions about the shooter before realising it must be John. Sherlock feigns shock to cover for John, telling Lestrade to ignore everything he has just said. Sherlock and John leave the scene but run into the man who had abducted John earlier, who turns out to be Sherlock's elder brother Mycroft. Mycroft instructs his secretary Anthea (Lisa McAllister) to increase their surveillance status, while Sherlock and John return to Baker Street.
Meanwhile, John obtains a job as locum at a local surgery with Sarah Sawyer. Sherlock and John discover a link between the two men; both had just returned from China, and both went to an oriental curio shop, "The Lucky Cat". There John discovers that the symbols are ancient Chinese Hangzhou numerals. Sherlock breaks into Soo Lin Yao's flat, obviously empty for several days. At the museum they discover the same symbols on a statue. Then, with the help of graffiti artist "Raz", Sherlock and John find more symbols painted on a railway yard wall, and struggle to decode the message.
Back at the Antiquities Museum, Holmes discovers Soo Lin in hiding. Soo Lin explains that the code is the work of the criminal "Black Lotus Tong", of which she was once a member. Unfortunately, before she can fully decode the message, the assassin, who is revealed to be Soo Lin's brother, strikes again. Sherlock realizes that Van Coon and Lukis were members of the Tong, involved in smuggling valuable antiquities from China to sell in London, and that they were killed because one of them stole something.
Sherlock knows that the message is in the form of a book cipher, and he and John spend the night going through the first two victims' books trying to find the solution. John's first day at work does not go well, as, having stayed up all night, he falls asleep in his consulting room. Sarah covers for him, and Sherlock arranges a date for the three of them at a traveling Chinese circus. While John and Sarah enjoy the classic escapology and acrobatics acts, Sherlock snoops around backstage and is attacked, but with Sarah and John's help, the three escape. While Sherlock continues to search for the solution to the book cipher, John and Sarah are kidnapped, Sarah is bound and gagged and then set in front of a giant time-delayed crossbow that will soon shoot her. The villains believe that John is Sherlock, and that he can be forced to reveal the location of the missing "treasure" in return for his girlfriend's life. Fortunately, Sherlock finds the solution to the code using an A-Z London Street Atlas guide, reads the message, tracks down the villains to their hideout and rescues John and Sarah. He also realizes that the elusive "treasure" has been in plain sight all the time: a jade hairpin being worn by Van Coon's secretary/mistress Amanda, who had received it as a gift from Van Coon.
However, Shan, the leader of the gang, escapes, making excuses in her report to her superior, who is identified only by the initial "M". The episode ends with Shan's assassination by a sniper sent by "M".
Sherlock is called to Scotland Yard. There, he is given a phone like that of the murder victim in "A Study in Pink". It plays five Greenwich pips and displays a photo of the basement flat of Sherlock's and John's building. There is a pair of trainers in the flat. A terrified woman, obviously reading a message from a third party, telephones. If Sherlock does not solve the puzzle in 12 hours, the explosive vest she is wearing will be detonated. Sherlock believes the five pips mean that he will be required to solve five challenges.
Sherlock and John examine the trainers. They are interrupted by Molly Hooper, a lab tech with feelings for Sherlock. She introduces her new boyfriend Jim, an IT employee; Sherlock deduces that Jim is gay, and tells her. The shoes belonged to a schoolboy named Carl Powers, who had drowned. Sherlock, underage at the time, had been interested in the case, but unable to convince the police. He solves it from clues left on the trainers: Carl Powers was poisoned via his eczema medication. The booby-trapped woman is freed.
A second message shows a sports car, stained with blood. Another hostage gives Sherlock 8 hours to solve the mystery. The card of a rental agency is in the glove box. The agency owner has a distinct suntan and was recently in Colombia, and the blood in the car had been previously frozen, so Sherlock concludes that the lost man, Ian Monkford, paid the agency owner to help him disappear. Once again, the hostage is freed. Sherlock is convinced that his battle of wits is with the mysterious Moriarty, named by the killer in "A Study in Pink".
Next, Sherlock investigates the death of Connie Prince from tetanus. Supposedly, she cut herself on a nail, but the wound was made after her death. A blind woman calls, giving Holmes 12 hours in which to solve the crime. Sherlock pins the crime on the housekeeper, who murdered Prince by increasing her botox injections. Although Sherlock solves the puzzle in time, the bomber triggers the explosives when the hostage starts describing her kidnapper's voice.
A photograph of the River Thames is fourth. Sherlock finds the corpse of a security guard there. A pair of bruises on the body are trademarks of "the Golem", an assassin. The guard had realised that a recently discovered painting by Vermeer was a fake. An astronomy professor had talked to the victim about the painting, and is also targeted by the Golem. While Sherlock and John fail to save her life, they find a clue to prove the painting is a fake, saving a fourth victim. The museum curator tells Sherlock that the person ultimately in charge was called Moriarty.
Investigating Mycroft's Andrew West case on his own, John is puzzled to hear that little blood was found on the tracks. Sherlock agrees that West was killed elsewhere, then dumped on the roof of a train. They confront West's prospective brother-in-law, who confesses that he stole the flash drive and accidentally killed West.
Sherlock waits for John to go out and then arranges to meet Moriarty. He is met instead by John, who appears to taunt him before revealing that he is another hostage, wearing an explosive vest and having his words dictated. Moriarty shows up and turns out to be Molly's boyfriend Jim. John grabs him, but lets go when a sniper aims at Sherlock. Moriarty leaves momentarily but soon returns, having multiple snipers target both Sherlock and John. Sherlock aims his handgun at Moriarty, but then changes his aim to the explosive vest, which he had thrown across the pool deck. The episode ends on this cliffhanger.
Six months later, Sherlock learns (via text message) that Adler has sent him her phone (which requires a code that he does not know to unlock), and realises she will be found dead; her mutilated body is later found and identified. Some time later, John is contacted by Mycroft Holmes' assistant, who takes him to the abandoned Battersea Power Station. Expecting to see Mycroft, he is surprised to find Adler, who faked her death to shake off the people who are out to kill her for the phone. Sherlock, having followed him, is now also aware of Adler's survival. Sherlock returns home to find that Nielson's team are making another attempt to take the phone, by imprisoning his landlady Mrs Hudson. Sherlock tricks and overpowers Nielson, and throws him out a window. Later on, Adler reveals that she is still being hunted and asks Sherlock to decipher a code she stole from a Ministry of Defence (MOD) official. He effortlessly cracks the code, revealing it to be an airline seat allocation number. Adler secretly texts the flight information to her contact, Moriarty, who in turn texts Mycroft, revealing that he is now aware of the MOD ploy to fool a terrorist cell that was attempting to bomb a plane.
Adler's attempts to seduce Sherlock are interrupted by government officials who have come to collect him and deliver him to Heathrow Airport. Sherlock remembers Mycroft mentioning "Coventry" on the phone and reminisces about the allegations that the British government allowed the Coventry Blitz to happen, so as not to alert the Germans that their military codes had been cracked. His suspicions that a similar situation is occurring are confirmed by Mycroft; the US and UK governments have decided to fly a 'dummy plane' full of corpses so as not to alert the terrorists while avoiding casualties. However, as Sherlock unwittingly helped Adler and therefore Moriarty crack the code, the scheme was foiled. Adler reveals a list of demands to Mycroft, including protection, in exchange for the release of the information on her phone. Adler further taunts Sherlock by revealing that he meant nothing to her. However Sherlock realises she is lying, as he previously took her pulse that proved otherwise. He opens the phone with the password "SHER" (so that its screen reads "I am Sher-locked"). With her leverage gone, Adler pleads for protection, as she is unlikely to outrun her enemies, but Sherlock and Mycroft turn her down.
Some months later, Mycroft informs John that Adler has been beheaded by a terrorist cell in Karachi, Pakistan, but asks him to tell Sherlock instead that she has entered a witness protection program in America. Sherlock appears to accept this and asks John to give him Adler's phone. After John leaves, it is revealed in a flashback that Sherlock actually went to Pakistan to pose as her executioner, revealed himself to her, and rescued her.
That night, Henry tells John and Sherlock about the words "Liberty" and "In" in his dreams. Sherlock, John and Henry then visit the hollow in the hope of confronting the hound. On the way, John notices what seems to be Morse code signals in the background (these were unrelated; they were headlight flashes from a group of doggers). When Sherlock and Henry arrive at the hollow, they both feel a sense of abject terror, and the trio leaves. At a local inn, Sherlock is visibly shaken and confesses to John that he saw the hound. A sceptical John tries to calm him, suggesting that he is imagining things. Sherlock reacts with anger, denying that there is anything wrong with him. John tries to interview Henry's therapist, Louise Mortimer. However, during the interview, they are interrupted by Frankland, who blows his cover. Meanwhile, Henry appears to hallucinate about the hound in his home.
The next morning Sherlock realises that "hound" may be an acronym rather than a word. The pair run into Inspector Lestrade (Rupert Graves), who was sent by Mycroft to keep an eye on Sherlock. They interrogate the innkeepers about a past order for meat that John has spotted, which struck him as odd for a vegetarian restaurant. The proprietors own up to keeping a dog on the moor to boost the tourist trade, but assure the investigators that they had put it down because it was uncontrollable. This explanation satisfies Lestrade but not Sherlock, who insists that the dog he saw was monstrous.
After calling Mycroft, Sherlock gains access to Baskerville again. While searching the lower levels of the genetics labs, John finds himself trapped and then hears growling which he immediately assumes is the hound. Locking himself in one of the empty cages, he calls Sherlock, who eventually rescues him. Sherlock deduces that a chemical weapon designed to trigger violent hallucinations was responsible. Retreating into his "mind palace", a memory technique, Sherlock realises that "Liberty" and "In" stands for Liberty, Indiana. After viewing confidential files, he sees that "H.O.U.N.D." was a secret military project in Liberty aimed at creating a hallucinatory weapon, but the project was shut down several years before - and that Frankland participated in it.
After John receives a call from Mortimer that a rampaging Henry has run away with a pistol, John, Sherlock and Lestrade run to the hollow to find Henry about to commit suicide. Sherlock manages to talk him out of it, explaining that hound was a hallucination; his father was actually killed by Frankland wearing a gas mask and a jersey with "H.O.U.N.D. Liberty, In" on it. After the murder, Frankland silenced Henry with the weapon: the hallucinogen, which metabolised quickly and therefore was not detected, made him appear insane and doubt his own memories, so that his story would be doubted by the authorities. The chemical agent also produced the fog they encountered at the hollow; it was triggered by pressure pads in the area. As Henry calms down, they all see what they perceive is the hound (in actuality the dog that the innkeepers could not bring themselves to kill after all, which the gas makes appear as a demonic monster). As they shoot the dog, Sherlock finds Frankland who attempts to flee but runs into the base's minefield and is blown up.
As Sherlock and John prepare to return to London the next morning, John wonders why he saw the hound in the lab despite not having inhaled the gas from the hollow, but later realises that Sherlock locked him in the labs in order to test his theory of the chemical agent.
In the closing scenes, Mycroft oversees the release of Jim Moriarty from a holding cell in which he has written Sherlock's name all over the walls.
Meanwhile, Moriarty proceeds to break into the case where the Crown Jewels are kept, while simultaneously opening the vault at the Bank of England and unlocking all the cells at Pentonville Prison via his mobile phone. Before smashing the Crown Jewels' case, he writes the words "Get Sherlock" on the outside, to be seen by the security cameras. He then allows himself to be caught wearing the jewels and sitting on the throne.
Sherlock is called to testify at Moriarty's trial. Though Sherlock explains that Moriarty is a criminal mastermind, Moriarty has threatened the families of the jurors. After being acquitted, Moriarty visits Sherlock and tells him, "I owe you". Meanwhile, John is summoned to see Mycroft, who explains that some professional assassins have moved into flats on Baker Street and asks him to watch out for Sherlock.
Sherlock and John investigate the kidnapping of the children of the British Ambassador to the U.S., part of a plot by Moriarty to make others suspect that Sherlock has been staging all his cases himself. He has traumatised the girl so she is terrified of Sherlock when seeing him, causing Sergeant Donovan to suspect Sherlock. A reluctant Lestrade is forced to arrest Sherlock, but Sherlock escapes with John handcuffed to him as his 'hostage'. They realise Moriarty's "Get Sherlock" has convinced the criminal underworld that Moriarty has given Sherlock the computer code he used to pull off his triple heist, a code that can bypass all security systems.
Sherlock and John break into the house of a journalist poised to publish an exposé on Sherlock. There, they find that Moriarty has developed a fake identity, Richard Brook (or Rich Brook, "Reichen Bach" in German), an actor whom Sherlock supposedly paid to pose as a master criminal. Now a wanted man with his media image on the verge of plummeting, Sherlock launches a final gambit. Leaving John, Sherlock contacts Molly at the hospital, and tells her he needs her help. John goes to the Diogenes Club to question Mycroft and learns that Mycroft divulged Sherlock's personal information during interrogations of Moriarty. Meanwhile, Sherlock deduces that the anti-security program was encoded in the tapping of Moriarty's finger during his earlier visit.
John finds Sherlock at the Bart's lab but leaves again after hearing Mrs Hudson has been shot. Sherlock texts Moriarty, who meets him on the roof of the hospital to resolve what the criminal calls their "final problem". Sherlock claims that, with the code, he can erase Richard Brook electronically. Moriarty reveals that there is no code, he just bribed security men, and that Sherlock must commit suicide or Moriarty's assassins will kill John, Mrs Hudson and Lestrade. Sherlock realises that Moriarty has a fail-safe and can call the killings off. Sherlock then convinces Moriarty that he is willing to do anything to make him activate the fail-safe; after acknowledging that he and Sherlock are alike, Moriarty tells Sherlock "As long as I am alive you are safe," then commits suicide by shooting himself in the mouth, thereby denying Sherlock knowledge of the abort codes and the ability to prove that Moriarty does exist. St Bartholomew's Hospital
With no way to use the fail-safe, Sherlock calls John, who is rushing back from 221B Baker Street after realising the report about Mrs Hudson was a ruse. Claiming that he was always a fake and explaining this last phone call is his "note", Sherlock throws himself from the roof of St Bartholomew's Hospital as John looks on from the street, thereby ensuring that Moriarty's true identity dies with him. After being knocked to the ground by a cyclist, John stumbles over to watch, in a daze, as Sherlock's bloody body is carried away by hospital staff.
The episode returns to John's therapy session, where he is unable to open up. Mycroft is shown reading the tabloid newspaper The Sun with a front page headline "Suicide of Fake Genius." Later, John visits Sherlock's grave with Mrs Hudson. There, heartbroken, he reaffirms his faith in Sherlock and begs him not to be dead. However, as he walks away, Sherlock - having somehow survived - looks on from the shadows before also walking away.