On April 20, 1841, the first detective story was published, "The Murders in the Rue Morgue" by Edgar Allan Poe. Many of the story's elements would be adopted by later authors as the genre developed: the genius detective, the first-person narrating sidekick, the red herring... "Rue Morgue" is also known as the first "locked room" mystery.
The story's opening paragraphs, distinguishing analysis from ingenuity, are still inspiring.
More background from Wikipedia. The full text of the story is available here.