Detective Inspector Lestrade is about wrap up an 18-month pursuit of elusive bank robbers when he receives two desperate texts: “HELP. BAKER ST. NOW.” “HELP ME, PLEASE.” Dropping everything, Lestrade rushes to Baker Street to find Sherlock in the grips of the hardest problem he has ever faced: writing a best man’s speech for John Watson’s wedding.
The big day is here, and as Sherlock dons his wedding suit, another man puts on his military uniform, dressing with one hand because his left arm is paralyzed. His face is also deeply scarred on the left side. John is delighted and surprised to see the soldier at the reception—it is his old friend and former commanding officer Major James Sholto, who rarely appears in public, and lives as a recluse “in the middle of nowhere."
Sherlock struggles to begin his speech, but finds his feet by attacking the occasion itself: “A wedding, in my considered opinion, is nothing short of a celebration of all that is false and specious and irritating and sentimental in this ailing and morally compromised world.” After this outburst, Sherlock states the obvious: he is an irritating and obnoxious man who is lucky to have a friend, any friend, but particularly lucky to know a man as good and as brave as John. As the guests break into tears, Sherlock consults his list of funny stories about John, recounting some of the cases he and John have taken on, in particular The Bloody Guardsman.
In a flashback we see Sherlock and Mary planning the seating arrangement for the reception. As Sherlock fusses over how to fold the napkins, Mary takes John aside and urges him to get Sherlock out on a case. Sherlock chooses the case of Private Stephen Bainbridge, a member of the Queen’s Personal Guard who believes someone is stalking him. Sherlock and John go to check it out, and see the grenadiers in their red uniforms and tall black hats standing impassively as tourists stand beside them for photos. Sherlock learns that Major Sholto led a team of new recruits into battle and it went wrong—they all died, Sholto was the only survivor, and the families of the dead soldiers went after the major, who gets more death threats than Sherlock, according to John. They find Bainbridge outside a shower stall, lying in a pool of blood and broken glass, clinging to life.
Flashing forward to the wedding, Sherlock moves on to The Mayfly Man, another particularly baffling case. It begins with another flashback to Sherlock asking Molly to calculate the ideal amount of alcohol he and John should have at each bar they are planning to visit for John’s stag night to avoid getting sick (it’s 443.7 milliliters). After drinking at a bar in every street where they found a corpse during their adventures, Sherlock and John return home completely drunk in just two hours.
They are not in top form when a client arrives saying she has dated a ghost: a man who had apparently died a week before she met him. But the next day, Sherlock follows up on the ghost story, and makes a list of women who claim they have dated a ghost. He questions four of them in a theater, trying to find something that will connect the women, when he is interrupted by John, and Sherlock is revealed to actually be standing in front of four laptops, online chatting with each woman. After the interruption, Sherlock returns to the mental theater he has constructed and continues his questioning. Nothing links the women and their stories, and all Sherlock can find is that the man steals the identities of recently deceased men that he looks up in the Obituaries—he is the mayfly, who lives for only one day. Finally, Sherlock asks all the women one question: "Do you have a secret you’ve never told anyone?" When they all say no, far too quickly, Sherlock knows they do have a secret, the same secret, that links them and attracts the Mayfly.
Flashing forward to the wedding, Sherlock proposes a toast to John and Mary, but as the photographer steps forward to capture the moment, Sherlock remembers that the client who first came to them knew John’s middle name, Hamish. The same client also signed off their online chat saying, “Enjoy the wedding!” Somehow, she had seen the wedding invitation that included John’s middle name—the Mayfly Man had the invitation, and so the Mayfly Man is there before Sherlock at that moment, at the wedding, and so is his victim. Sherlock desperately continues to talk in order to keep anyone from leaving the room as he tries to deduce which of the guests is the Mayfly, or the potential victim. At last he has the victim: Major Sholto. A recluse with a small household staff of four women, whose secret is that they work for this haunted and hunted man.
While Sherlock is deducing this, Sholto leaves the hall and locks himself in his room, ready to end it all at last. Mary commands Sherlock to solve the mystery, and suddenly he has it: Major Sholto was already injured several hours ago. Like Private Bainbridge, Sholto wears a thick military belt high on the waist. Both men were stabbed by a long, thin knife through the belt, and the pressure of the tight belt prevented the wound from bleeding until the belt was removed. Bainbridge took his belt off when he undressed for his shower, and began to bleed to death in the locked stall. Sholto too would die once he undressed. Sholto is tempted to take off the belt and end his miserable life, but Sherlock convinces him not to end his life at John’s wedding. Sholto agrees to let John help him, and his life is saved.
In the lobby downstairs, Sherlock confronts the wedding photographer—the man they saw all the time but never really saw, as his face was always behind the camera. Photographer Jonathan Small is revealed to be the Mayfly Man, whose brother was killed in the action with Major Sholto. Small rehearsed the murder with Bainbridge, then stabbed Sholto while posing him for a wedding photo.
Sherlock plays the waltz he composed for John and Mary’s wedding dance, and then makes one last speech in which he promises always to protect the three of them—he alone has deduced that Mary is pregnant.