Sherlock won because he didn't play to win, he played to lose. He didn't try to beat Moriarty. He knew Moriarty was too smart for him to be able to outfox at every turn. So he played to lose, let Moriarty's game play out the way Moriarty wanted it to, he planned around losing, and that is how he won.
WELL PLAYED, SHERLOCK. WELL PLAYED.