“Moriarty” shot himself. Well, Jim shot himself. For the greater good. He’s dead, really. But he wasn’t Moriarty. The real one didn’t die, the body double did. Jim. He was the body they needed to drag away. Sherlock keeps saying he’s dead: he shot himself in the head, of course he’s dead. “But what’s Moriarty planning next…” so Jim wasn’t Moriarty. Moriarty is alive.
The real Moriarty knew Sherlock wasn’t really dead either. And if Sherlock would come back to anyone, it would be John. So the real Moriarty stayed as close to Sherlock’s only friend in the world as possible. Married him even.
Both Moriarty and Jim have now worn the same wedding dress.
Mary is definitely Moriarty.
Explains why she outsmarted Sherlock and even Mycroft on the plane.
EDIT - also Sherlock admitted at the end he was only NOW catching on to Mary; Mycroft already knew about her.
EDIT 2 - “I will burn the heart out of you” - she married John, she actually burned the heart out of him, hurt him more than any other criminal ever did. John doesn’t even live with Sherlock anymore because of her. She tried to break them up, break the team up, because they’re stronger together.
EDIT 3 - Moriarty has a twin brother in the books. “Sister! There’s always something!”