Newspaper magnate Charles Augustus Magnussen is being interrogated about his relationship to and potential influence on the British prime minister by a government panel led by Lady Smallwood. He evades their questions, all while seeming to read information about each member of the panel on a digital screen—names, financial status, and, most importantly, pressure points. In Lady Smallwood’s case, the pressure point is her husband. Confronting Lady Smallwood in her office, Magnussen promises to blackmail Lady Smallwood with incriminating letters her husband wrote years ago. Lady Smallwood seeks out the one person in England who can stop Magnussen—Sherlock Holmes.
Early morning finds John Watson retrieving his neighbor’s son from a crack house. John finds Isaac after twisting the arm of a junkie who threatens him with a knife. He also finds Sherlock, presumably undercover, but possibly relapsed into drug abuse. He takes Sherlock to the lab to take a drug test, which he fails. The junkie whose arm was twisted, Bill Wiggins, is there too, receiving treatment.
Sherlock returns home to find Mycroft overseeing a search of his apartment for drugs. Mycroft asks suspiciously why Sherlock’s bedroom door is closed for the first time in his life. After throwing Mycroft out, Sherlock disappears into the bathroom, and Janine, the maid of honor at John and Mary’s wedding, opens the locked bedroom door, wearing only a shirt of Sherlock’s. She asks if Sherlock was fighting with “Mike” again, and complains lovingly about how long “Sher” always takes in the shower. Once Janine is gone, Sherlock tells John that Magnussen’s repository of blackmail information, called Appledore, is located inside his home. None of it is on a computer—computers can be hacked—it’s all in hard copy in the repository underneath his house. John’s mystified puzzling over Janine is interrupted by the arrival of Magnussen himself to negotiate the return of the Smallwood letters. Magnussen says he will keep the letters, but Sherlock sees that he has brought them with him from Appledore. While Magnussen is out to dinner, the letters will be locked in the safe of his London office, and then Sherlock and John will break in and steal them.
Janine is revealed to be Magnussen’s personal assistant, and she buzzes Sherlock in when he shows her an engagement ring. As they ride the elevator to Magnussen’s office Sherlock tells John that he was using Janine all along to get to her boss. When they reach the top floor, they find Janine and a security man unconscious on the floor from blows to the head, and the scent of Clair de Lune perfume in the air. As John looks after Janine, Sherlock goes into Magnussen’s private office and finds him on his knees before a masked gunman—Lady Smallwood carrying out her own revenge? No, it is Mary Watson, who makes good on her threat to shoot Sherlock if he takes one more step toward her.
As the bullet does its work, Sherlock goes into his mind palace—an assembly of memories and information from a variety of people he knows. Molly, Mycroft, and even Anderson give him information to stop the bullet from dislodging, and the pain even conjures up Moriarty, bound in chains and a straitjacket. By now John has found Sherlock, who nearly dies, but when he regains consciousness in the hospital his first word is “Mary”. Janine arrives, with tabloids that blare her story of sex and mayhem at 221B—she used Sherlock to make a fortune selling her story, just as he used her to get close to Magnussen. Back at Baker Street, John begins to think about the fact that Sherlock was facing the gunman, and must know who it was is. On a dark London street Mary meets Sherlock, who tells her story: she stole the identity of Mary Morstan, a woman who died decades before. Mary admits it all, only to find that the figure at the end of a hallway who she thought was Sherlock was actually John. Flash forward to Christmas at the Holmes cottage: Sherlock, Mycroft, and their parents are celebrating Sherlock’s recovery, some more willingly than others. Mary is also there, alone. John appears. Flash back to the night of Mary’s revelation, where, back at Baker Street, Sherlock persuades John to treat Mary as a client who needs to tell her story.
Christmas Day again, and John holds out a thumb drive to Mary, which upsets her deeply. We see in flashback that the drive, labeled “A.G.R.A.”—her real initials—holds all the information about Mary’s past. She was an intelligence agent who tried to disappear but Magnussen discovered her secret. She was planning to kill him when Sherlock showed up, and she could have killed both him and Magnussen and left. But once she knew John was there, too, she realized he would be blamed for the murders. She strategically wounded Sherlock so that he would not be conscious when she negotiated with Magnussen for his silence. Then she knocked Magnussen out and called for an ambulance for Sherlock, saving his life.
Flash forward, and John throws the drive into the fire, unread. Moments later, Mary collapses in John’s arms, and John finds the entire family are passed out. Sherlock tells John they are going to Magnussen’s house with Mycroft’s laptop to trade it for access to Appledore and Mary’s documents. Magnussen reveals that he kidnapped John and put him in the bonfire to test how important a pressure point he was for Sherlock. Sherlock demands Mary’s documents once Magnussen has the laptop, and Magnussen leads them to a small closet. He opens it to reveal—nothing but a chair. Appledore, it turns out, is Magnussen’s mind palace: all his information is kept entirely in his head, so that it can never be stolen or destroyed, or used in court against him. Now Sherlock has nothing, Magnussen has the laptop, and he has called the police, who will arrive to find Sherlock and John trying to sell state secrets. As the helicopters arrive, Sherlock asks Magnussen to verify that Appledore exists only in his mind—and then shoots Magnussen through the head.
In a government office, Mycroft explains that Sherlock is being sent to eastern Europe on suicide mission. Sherlock says goodbye to John on the tarmac and boards the plane. Meanwhile in London, Greg Lestrade is watching a soccer game at a pub when the screen distorts; through the static, he sees a face—every video screen and television set in England is showing it. Mycroft gets the call on the tarmac, and he calls Sherlock on the plane to tell him he’s needed. “Who needs me this time?” asks Sherlock. As Mycroft watches an animated photo of Moriarty’s face repeating “Did you miss me?” over and over, he replies, “England.”