John goes to see his therapist Ella for the first in eighteen months, prior to his moving in with Sherlock. She wonders why he came back and John says that if she's kept up on the news then she knows why. Ella tells him to talk about what happened, saying that he needs to get it out, and John finally admits that his best friend, Sherlock Holmes, is dead.
Three Months Earlier
Sherlock's public reputation grows as he recovers a stolen painting, The Falls of Reichenbach. He subsequently rescues an abducted family man and brings an international criminal, Ricoletti, to justice. Lestrade is forced to honor him on behalf of Scotland Yard, and presents him with a deerstalker hat.
At Baker Street, neither John nor Sherlock are happy at the press attention: Sherlock hates the deerstalker and John isn't happy being identified as a "confirmed bachelor." He warns his friend that the press will soon on him like they do with any celebrity. Sherlock is puzzled as to why John is so concerned about what people will think of him, but John just tells him to find a small case to solve.
Just before 11 a.m., Moriarty poses as a tourist and enters the Tower of London to see the Crown Jewels. He texts Sherlock, who is busy with lab work and ignoring his phone. Once he gets to the display case, Moriarty puts on a pair of earphones from his iTouch and brings up a computer key code. He sends it first to the Tower security computers and the power goes out. As the door starts to steal, Moriarty knocks out the guard sent to escort him out and is trapped within. Next, Moriarty sets off the alarms at the Bank of England using the same key code, and finally he releases the prisoners at Pentonville Prison. Meanwhile, he writes "Get Sherlock" on the display case, uses gum to stick a diamond to the shatterproof glass, and hits it with a fire extinguisher.
Lestrade and Davidson have received all three alert and finally responded to the one at the Tower. When they arrive with a squad of men, they burst into the display room and find Moriarty sitting in the case, wearing the Crown Jewels and waiting for them.
John finally checks Sherlock's phone and shows him the text message. It's from Moriarty inviting Sherlock to come play with him at Tower Hill. They go there and examine the security footage, which shows Moriarty writing Sherlock's name on the glass and then shattering it.
Moriarty goes to trial and Sherlock is summoned as a witness. The press are following the trial, and Sherlock's participation, with keen interest. When he goes to the restroom at the Old Bailey, a young woman wearing a deerstalker hat and a Sherlock fan pin comes in and asks him to sign her chest. However, Sherlock realizes from the clues that she's actually a journalist. The woman introduces herself as Kitty Riley and Sherlock immediately tells her that he doesn't do interviews. When Kitty threatens to publish rumors about Sherlock and John's love life if he doesn't cooperate, Sherlock tells her to read him if she's so smart. She's unable to do so and Sherlock analyzes her further, saying she's a novice journalist desperate for a story. He says that she repels him and leaves.
In court, Sherlock alternately corrects the prosecuting barrister on proper procedure and warns that Moriarty is not a man but a spider at the center of a criminal web. When the judge informs him that it's up to the jury to decide, Sherlock analyzes each of the jury members and points out that they're not qualified. The judge tells him to stop showing off or face a contempt charge, or end up in a cell. Sherlock is soon in a jail until John bails him out. John points out that Moriarty isn't mounting a defense and Sherlock concludes that his nemesis is in jail because he wants to be there.
The next day, the defense barrister closes his case without providing any witnesses or evidence. The judge advises the jury to find Moriarty guilty. However, they return only six minutes later and declare him not guilty. John calls Sherlock at home and warns him that Moriarty will come after him. Sherlock calmly makes tea and plays the violin, and Moriarty comes in without knocking. He sits down and has tea, and reasons that Sherlock must be glad that he's out so that he has a proper fairy tale villain to oppose. Moriarty then explains that he threatened all twelve jurors into finding him not guilty via their hotel cable channels, and Sherlock wonders what he has planned for him. Moriarty, tapping on his knee, says that disposing of Sherlock is his final problem and asks if Sherlock has worked it out.
When Sherlock doesn't answer, Moriarty asks if he know why he penetrated the security at the three locations. Sherlock deduces that Moriarty didn't need anything from the locations because he has the key code that can get him into anything, anytime, and let him take anything he wants. Moriarty staged the attacks to advertise his key code to terrorists and rogue governments, and Sherlock helped him. Sherlock figures that he wants more than that and his nemesis says that what he really wants is to solve the final problem, their problem. Moriarty tells Sherlock that he will soon begin his fall and that he owes him, and then walks out of the apartment.
Two Months Later
John is taking money out of his ATM machine when it informs him that there's a problem with his card and addresses him by name. A car pulls up and delivers him to the exclusive Diogenes Club. When John tries to ask for Mycroft, the members all reject in abject horror, summons servants, and have John gagged and escorted to Mycroft. As Mycroft explains that total silence at the club is traditional, John notices that he has a tabloid paper with an article by Kitty promising an expose on the Great Detective.
Moving onto business, Mycroft shows John photos of a man who has moved into an apartment on Baker Street and explains that he is one of four international assassins that are recent tenants. He suspects that Moriarty is responsible but John points out that if Moriarty wanted them dead, they'd already be dead. He suggests that Mycroft talk to Sherlock but Mycroft warns that there is too much history between him and his brother. As John leaves, Mycroft asks him to look after his brother as they both know that Moriarty won't stop until Sherlock is destroyed.
When John returns home, he discovers a brown envelope with a red wax seal, and opens it to discover bread crumbs. Disregarding it, he brushes past a workman and goes upstairs to find Lestrade and Donovan with Sherlock. The U.S. Ambassador to England, Bruhl, has asked Sherlock, the "Reichenbach Hero," to investigate the abduction of his children Claudia and Max from their boarding school on the first day of holidays.
At the school, Sherlock berates the headmistress, Miss MacKenzie, to get her to quickly answer his questions. Once she confirms that all of the doors and windows were locked, Sherlock first goes to Claudia's room and looks around. He finds a brown envelope with a red wax seal, unaware that it's similar to the one that John found earlier. Inside it is a book of Grimm's Fairy Tales.
When Sherlock examines Max's room, he realizes that the boy would have seen and recognized any strangers at the pebbled window. He finds the boy's collection of spy books and figures that Max would have left a clue, and then smells the linseed oil that Max used to treat his cricket bat. Using Anderson's UV lights, Sherlock discovers that Max has written the words "help us" on the wall by his bed, and then covered his feet in the linseed oil. The kidnapper walked behind Max as he lead him away, leaving his own footprints as well. The trail peters out and Sherlock takes samples from the floorboards, while John points out that his friend is enjoying himself despite the fact that children are at risk.
As they return to London, Sherlock explains that the kidnapper slipped in with the parents picking up their children on the day before and hid until he could get to Max and Claudia. Sherlock then takes his friend to St. Bartholomew's and asks Molly to help them with the footprint samples, reminding her that she used to date Moriarty. The oil samples contain traces of chalk, asphalt, brick dust, vegetation, and an unidentified glycerol molecule. As he works, Sherlock echoes Moriarty's earlier words, "I owe you," and Molly overhears him. When he refuses to explain, Molly says that she could tell when her dying father pretended to be okay but she could tell the truth, and that she can tell that Sherlock also isn't okay. When she offers him anything he might need, Sherlock wonders what he could need from her and Molly quickly walks away.
As John examines the crime scene photos, he sees the brown envelope and recognizes it as the same one that the bread crumbs came in. He tells Sherlock, who realizes the bread crumbs relate to the story of Hansel and Gretel, which was in Claudia's book in the second envelope. Sherlock also remembers Moriarty referring calling himself a fairy tale villain, and realizes the glycerol molecule is found in chocolate.
At an abandoned sweets factory, the hungry kidnap victims are desperately eating chocolate.
Lestrade informs Sherlock and John that they've received a fax from the abductor, telling them to hurry because the children are dying. They go over the five elements and try to find the one location where they can all be found. Sherlock calls upon his homeless network and eventually locates a sweets factory in Addlestone. When they arrive, they find empty sweets wrappers and a recently lit candle. The wrappers are painted with mercury, not enough to be toxic from a single wrapper. Sherlock realizes that the hungrier the children were, the faster they would eat and guarantee their own deaths. Donovan finds the children nearby, moaning in pain, and the police get them to the hospital.
Lestrade and Donovan get nothing out of Claudia, while Max is unconscious. Sherlock goes in but Claudia starts screaming as soon as she sees him and Lestrade hastily gets the detective out. They assume that Claudia is traumatized from the abduction and the poisoning. As Sherlock leaves, Donovan points out how unlikely it was that Sherlock could have tracked the children down working from a single footprint. Thinking, Sherlock tells John to take the next cab because he needs to think. Meanwhile, Donovan goes over the case photos and Donovan asks her if there's a problem.
The taxi TV comes on and Moriarty appears to address Sherlock. He is on what appears to be a children's TV set and starts talking about the tale of Sir Boast-a-Lot. Moriarty describes how the other knights grew to hate Sir Boast-a-Lot because he always boasted about his genius, and finally didn't believe his stories.
Donovan notes her suspicions about Sherlock's deductions to Lestrade, saying there may be another explanation. She suggests that Sherlock is the kidnapper and Anderson agree with her.
Moriarty finishes his story and says that the other knights aren't Sir Boast-a-Lot's final problem. As the cab arrive at Baker Street, Sherlock tells the driver to pull over and then goes to the front window. The driver is Moriarty, who waves and drives away before Sherlock can break the window. As Sherlock stares after him, a car almost runs him down but a pedestrian pulls him out of the way. As Sherlock turns to thank him, two shots ring out and his savior drops to the ground, dead, just as John pulls up in another taxi.
The police and EMTs arrive at the crime scene, and John tells Sherlock that the dead man was one of the assassins that Mycroft had identified earlier. Sherlock deduces that the other assassins killed the first one because they want to make sure none of them get whatever it is that they think Sherlock has from Moriarty. He then goes to the apartment and looks around, realizing that they've been bugged. Sherlock finally finds a hidden camera in the bookcase. Lestrade comes up and Sherlock concludes that he's there to bringing him in for question, and that Moriarty has planted a seed of doubt in Donovan's mind. Sherlock refuse to go with Lestrade, who leaves as John watches him. John's friend warns that the police will undoubtedly get a warrant and come back to arrest him. John objects, saying that he doesn't want people to think that Sherlock is a fraud. However, he hesitates and Sherlock angrily points out that even John is starting to believe Moriarty's big lie. John assures his friend that he knows he's a great detective, since no one could fake being annoying all of the time.
At Scotland Yard, Lestrade and his team meet with the superintendent and tell him they've been using Sherlock as a consultant. The superintendent is shocked to have an outsider involved and tells Lestrade to arrest Sherlock immediately. However, as he leaves with a warrant, Lestrade texts John to warn him. Meanwhile, Mrs. Hudson has received another of the envelopes, this one containing a gingerbread man. Sherlock realizes what it means as the police arrive, handcuff him, and take him away over John's objections. Donovan reminds John that she told him from the beginning that Sherlock would eventually become a criminal. When the superintendent comes in and sees the disarray of Sherlock's workshop, he calls Sherlock a weirdo and John punches him. As he's taken down to the car and handcuffed to Sherlock, Sherlock realizes that they have to escape. He turns up the volume on a police car radio, deafening the officers long enough for him to grab a gun. Sherlock then takes John as a hostage and orders everyone down.
Sherlock runs for it with John in tow, dropping the gun, and John suggests they ask Mycroft for help. Reluctant to start reconciliation with brother, Sherlock notices that one of the assassins is following them. He steps in front of an approaching bus and the assassin lunges forward and shoves them out of the way. Sherlock grabs his gun and demands to know what they want from him, and the killer tells them that everyone believes that Moriarty gave the access code to Sherlock two months ago. Another assassin opens fire, killing Sherlock's captive. Sherlock pulls John into a nearby alley and tells him about the access code, and deduces that Moriarty hid it at the apartment during his last visit. Moriarty writing "Get Sherlock" on the case, knowing the footage would play to the world, was his message to the criminals, terrorists, and rogue governments that Sherlock had the code.
As they take a breather and try to work out what to do next, John sees the tabloid that Mycroft had at the club. In the article, Kitty says that Sherlock hired an actor, Richard Brook, and John wonders who Richard Brook is.
When Kitty comes home, she finds Sherlock and John in her apartment, handcuffed together and waiting for her. She claims that she doesn't know who Brook is and reminds Sherlock that she gave him a chance to trust her. Moriarty comes in and panics, and Kitty explains that Moriarty is supposedly Richard Brook, an actor that Sherlock hired to play the role of Moriarty. John points out that Moriarty tried to kill him, but Moriarty tells him that Sherlock staged the encounter at the pool as well. Kitty has exclusive proof of everything that Moriarty claims based on Sherlock's history, and says that Sherlock promised Moriarty that he would threaten the jury to get him found not guilty. John insists that it's not true but Moriarty has a resume showing that he's the storyteller-host of a children's show. When Sherlock tries to grab Moriarty, he runs into the next room and escapes via the window before they can stop him. As the two men leaves, Kitty echoes Sherlock's earlier words, telling him that he repels her.
Outside, Sherlock opens the handcuffs and warns John that Moriarty had created a big lie and used small facts to support it. He realizes that Moriarty has only one thing left to do and then leaves on his own, telling John that he has to do it on his own.
As Molly leaves the lab, Sherlock approaches her and admits that he's not okay and that he has always trusted her. When she wonders what he needs, Sherlock asks if she would help him if he wasn't what either one of them thought he really was. Molly simply asks again what he needs and Sherlock says that he needs her.
When Mycroft arrives at the club, he finds John waiting for him. John has already realized that Moriarty had to talk to someone close to Sherlock to get enough facts to make his big lie convincing. He has also figured out that Mycroft asked for his help because he was the one who told Moriarty what he needed. Mycroft admits that the government abducted Moriarty once they realized that he had the key code and tortured him for the information. The only time that Moriarty would say anything was when Mycroft talked to him, and that he demanded information about Sherlock in return for speaking. Disgusted, John walks away, ignoring Mycroft's request to tell Sherlock that he's sorry.
Sherlock calls John and has him come to the hospital. He figures that they can use the key code to prove that "Richard Brook" is false and tries to work out where and how Moriarty hid it. When John taps his fingers while concentrating, Sherlock remembers that Moriarty was tapping his fingers during his apartment visit. He sends a text message to Moriarty telling him to meet him atop the hospital and that he has something that belongs to him.
While the two men wait, John receives a call informing him that someone has shot Mrs. Hudson. He insists on going but is surprised and shocked when Sherlock refuses, saying that Mrs. Hudson is just his landlady. Angry at his friend, John calls him a machine and says that it's friends that protect each other. Once he leaves, Moriarty texts Sherlock to tell him that he's waiting.
When Sherlock goes to the roof, Moriarty explains that even Sherlock failed him in his quest to find distractions. Sherlock has already realized that "Reichenbach" is German for "Richard Brook," another of Moriarty's games. Moriarty sees Sherlock tapping his fingers and congratulates him on working it out. Sherlock explains his conclusion that Moriarty tapped out the access code in binary, and that the assassins want him alive because he knows the pattern. When Sherlock threatens to use the code to destroy the Richard Brook identity, Moriarty disgustedly tells him that he's wrong and that there is no code. The rhythm he tapped out was Bach's, and that he simply used inside help to commit the three crimes. He tells Sherlock that his one weakness is that he expects things to be clever. When Moriarty tells Sherlock that it's a good thing he chose a tall building to solve their final problem. Sherlock means that Moriarty intends him to kill himself now that his reputation has been destroyed.
John arrives at Baker Street and discovers that Mrs. Hudson is fine. She's chatting with the workman who came in earlier, and John goes outside to take a taxi back to St. Bartholomew's.
Sherlock grabs Moriarty, saying he's insane, and his nemesis says that it took him long enough to figure out. When Sherlock refuses to give up, Moriarty tells him that he has three killers targeting John, Lestrade, and Mrs. Hudson. They will only stop if Moriarty's people tell them that Sherlock has killed himself. Sherlock can do what he wants to Moriarty, but the criminal boasts that whatever happens, his only three friends will die.
Believing he has no choice, Sherlock steps to the edge and then asks for a moment of privacy. Moriarty grants it but Sherlock starts laughing. Startled, Moriarty demands to know what he missed. Sherlock steps back from the edge and says that Moriarty must have a recall code and he can get it from him. When Moriarty insists that there's nothing that he can do, Sherlock informs him that he may be on the side of the angels, but he's no angel. Satisfied, Moriarty says that Sherlock isn't ordinary and thanks him. As he shakes Sherlock's hand, Moriarty says that as long as he's alive, Sherlock can save his friends... and then takes out a gun and commits suicide.
The Baker Street worker, a sniper at the hospital, and one of Lestrade's underlings all prepare to kill their designated targets.
Shocked, Sherlock goes to the edge of the roof and sees John pull up in the taxi. He calls him and tells him to stay back. When John refuses, Sherlock tells him to look up, and then says that Moriarty is right noting all the deductions that Sherlock made when they first met. His friend dismisses them as a magic trick done with advance research, and tells John to tell everyone the truth. Crying, Sherlock tells his friend to watch no matter what and then steps off the roof and plummets to his death. John runs to his friend but a passing bicyclist knocks him down. Stunned, John staggers over to the corpse as a crowd gathers. He manages to check the body's pulse and confirms that his friend is dead before the EMTs take him away... unaware of how close to death he was as the assassin quietly leaves.
Sometime later, Mycroft reads Kitty's expose about the "great" Sherlock Holmes.
Ella asks John what it was that he wanted to say to Sherlock that he never did. John then goes to the cemetery with Mrs. Hudson to say goodbye to their friend. Mrs. Hudson, crying, is forced to step away. John tells the gravestone that Sherlock was the most human human being that he knew, and that he wants him to perform one more miracle: to come back to life. When he gets no answer, John turns and walks away... unaware that Sherlock is watching him.