On April 14, 1841, the first detective story was published, Edgar Allan Poe's "Murders in Rue Morgue". From the article:
"Edgar Allan Poe -- The Father of the Detective Story
Genesis: 1841
Edgar Allan Poe
Edgar Allan Poe was the undisputed "Father" of the Detective Story. He created so much that is of importance in the field -- literally creating the template for all of detective fiction to follow. (Years later, Sir Arthur Conan Doyle was to say that Poe "was a model for all time.")
In just three stories, Poe created the amateur detective and his narrator friend, the locked-room mystery, the talented but eccentric amateur sleuth outwitting the official police force, what Haycraft calls the "catalogue of minutia," interviews with witnesses, the first fictional case of an animal committing a perceived murder, the first armchair detective, the first fictional case which claimed to solve a real murder mystery previously unsolved by police, the concept of hiding something in plain sight so that it is overlooked by everyone who is searching for it (except for the detective, of course), scattering of false clues by the criminal, accusing someone unjustly, the concept of "ratiocination" (later called "observation and deduction" by Sherlock Holmes and others!), solution and explanation by the detective, and more. Other stories by Poe introduced cryptic ciphers, surveillance, the least-likely person theme (in one case, the narrator of the story is the murderer!), and other ingredients that have spiced up many a recipe for a crime story.
Poe also began the tradition so fondly embraced by connoisseurs of crime fiction -- what became known as "The Rules of the Game," which state, among other things:
(1) The detective story must play fair.
(2) The detective story must be readable.
The Detective Story, per se, was invented in the three stories which feature "the Chevalier C. Auguste Dupin." These are:
"The Murders in the Rue Morgue" (You can read an article about it here. or read the story itself for free in the Reading Room.)
"The Mystery of Marie Roget" (Read an article here.)
Other Poe stories, although embracing crime and/or mystery, are not true detective stories because they don't introduce all the clues (and so fail to meet the criterion of "playing fair" with the reader) until after the dénouement. Nevertheless, they introduced elements which have become standard in detective and crime fiction. These stories include:
"The Gold Bug," which introduced a cipher and the protagonist's attempt to solve it. (See an article here.)
"Thou Art the Man," was the first known inclusion of the use of ventriloquism to trick a suspect into confessing to a murder.
"The Man of the Crowd," which may well be the first story to include what later became known as "surveillance."
Poe's stories are available in his Tales.
Edgar Allan Poe Complete Tales and Poems contains the three detective stories that Poe wrote:
"The Murders in the Rue Morgue"
"The Mystery of Marie Roget"
"The Purloined Letter"
This book also includes other stories that influenced the genre, as described in the article above:
"The Gold Bug"
"Thou Art the Man"
"The Man of the Crowd""