Let's say our story is set in a city with especially corrupt law enforcement, both deep in the pockets of criminal organizations and prone to using brutal and illegal methods. The problem is that when they catch someone, they don't have a story to explain how they caught them without referencing their illegal tactics. This is where "master detective" Holmes enters the picture: The police make up some just-so story about an implausibly clever series of deductions from tiny details leading them to their quarry, and then attribute these deductions to Sherlock Holmes, a very helpful if somewhat reclusive genius. Holmes actually is a private detective, but an incompetent and luckless one who happens to have good acting skills. He's been in this deal with the police for the past several years, and they pay him handsomely for his "consulting services".
The arrangement started with relatively minor matters, such as explaining why the police knew which house to search. As Holmes' public profile grew, and people accepted that he was a deductive genius, the deduction stories grew more tenuous and elaborate. Watson, who writes up and publishes these stories, is the public relations man and fact-checker of the duo. He doesn't have Holmes' talent for theatrical delivery, but he makes sure that the stories are well-constructed, and has carefully managed Holmes' image.
This also explains Moriarty. Remember, the police aren't just brutal, they're also corrupt, so there's the occasional high-profile case they have no interest in solving. To explain why these cases remain unsolved, they are attributed to "Moriarty", a shadowy underworld genius of an intellectual caliber that outmatches even Holmes'. Unlike Holmes, who is a real person pretending to be someone he's not, Moriarty is fictional.
Except, one day, he isn't fictional anymore, and things get very... interesting.