The previous season of Sherlock focused more on Sherlock Holmes' emotional growth. Steven Moffat and Mark Gatiss, co-creators of the series, had almost humanized the high-functioning sociopath in Season 3, and his actions in the finale reflected that. He committed cold-blooded murder to protect his friends and family.
Season 3's diabolical villain Charles Augustus Magnussen (Lars Mikkelsen) had access to the upper echelons of British politics, including the British Prime Minister. He knew the pressure points of everyone, and that made him immensely powerful and invincible. Magnussen, the Napoleon of Blackmail, turned the table on a committee who was grilling him about his possible influence over the British Prime Minister. He blackmailed the head of the committee, Lady Elizabeth Smallwood (Lindsay Duncan), and threatened to expose her husband's affair with a minor girl. Now that he had leverage over her, he kissed and licked her face as an act of ownership.
Mycroft (Gatiss) stopped Sherlock from going after Magnussen, saying that he was not his business. And he also warned that if Sherlock ever went against the master blackmailer, he would find himself going against his brother. But Sherlock wouldn't be Sherlock if he followed his brother's dictates.
He began a relationship with Magnussen's personal assistant, Janine (Yasmine Akram), who was the bridesmaid at Mary (Amanda Abbington) and Watson's wedding, to break into her boss' office. Sherlock and Watson got inside the maximum security office by making Janine believe that he was there to propose to her. Inside the room, they found her lying in a pool of blood.
While Watson was attending to Janine, Sherlock walked up the stairs and witnessed one of the shocking sights of his life. He saw Mrs. Watson there. She was pointing a gun at Magnussen, who was kneeling down in front of her. The latter asked Mary to kill them both -- him and Sherlock.
Sherlock offered his help. He told Mary that whatever Magnussen had got on her, let him help her. Instead of accepting his offer, Mary shot him in the chest. Sherlock's mind palace kept him from losing his three-second of consciousness. He saw Molly (Louise Brealey), Mycroft, his old dog and Moriarty show up one after another in that mind palace.
After he had regained consciousness, Sherlock went looking for Mary, the CIA agent and assassin who had shot him with the intention to hospitalize him and not kill him. She wanted to kill Magnussen because he had some highly sensitive information on her. She was afraid that if Watson ever found out her secret, his love for her would evaporate. Sherlock told Mary that he would take her case.
Watson, on the other hand, was hurt and furious after he figured out that Mary was hiding something big from him, and that she was the one who shot Sherlock. She gave him a USB flash drive, which had A.G.R.A written on it, with a request attached. She told him to watch the footage when she was not around, as he would no longer love her after he had finished watching it.
Mary and Watson patched up at Sherlock's parents' home on Christmas. Watson threw the flash drive in the fire, saying that her past is not his business, but problems of her future are his privilege. Their moment of reconciliation was short-lived, as Mary soon fainted. And Watson discovered, to his horror, that Sherlock had drugged everyone.
Sherlock took Watson and Mycroft's laptop with him to meet Magnussen. They were going on an incredibly dangerous mission to keep Mary safe. He told Watson that one wrong move and they would be done, and the odds were stacked against them.
"One false move and we'll have betrayed the security of the United Kingdom and be imprisoned for high treason. Magnussen is quite simple the most dangerous man we've ever encountered and the odds are comprehensively stacked against us."
Mycroft soon arrived in a chopper, and a team of special force was already on the ground. They were not there to arrest Magnussen. Sherlock was the wanted man. He was going to be arrested on charges of selling state secrets, and it was all Magnussen's plan from the beginning to gain control over Mycroft, the most powerful man in the country.
But Magnussen had forgotten something about Sherlock, and as the latter reminded him after shooting him -- he too was a high-functioning sociopath. After killing the fiend, Sherlock told Watson that Mary was now safe.
Mycroft cut a deal with Smallwood to keep Sherlock out of prison. And as punishment, he was sending his little brother on a six-month exile to East Europe. But this exile just lasted for four minutes. Moriarty had appeared on television screens, repeatedly asking, "did you miss me." His resurrection meant Sherlock was very much needed in the country.