Sam Spade, Sherlock Homes, Miss Marple and even Monk owe their beginnings to Monsieur C. Auguste Dupin, better known as the detective in The Murders in the Rue Morgue. Edgar Allan Poe published what is considered the first true detective story on April 20, 1841.
Two women are brutally killed in a locked room with a chimney too small for a man to enter to leave by. Entrance or exit by the windows would be obvious, but they are still locked, too. So, how did they die and how did the murderer escape? It’s the perfect (and first) locked-room murder.
Monsieur Dupin uses deductive reasoning and the perfect little trap in the end to expose the killer. It is all narrated by a personal friend and the poor policemen come off looking a bit foolish in the end. Sound familiar? However, our friend Mr. Holmes wouldn't be published until 1887.
Poe also wrote two other stries about Monsieur Dupin: The Mystery of Marie Roget (1842) and The Purloined Letter (1844).
Project Gutenberg: The Works of Edgar Allen Poe, Vol. 1
Classic Crime Fiction: Origins of Detective Fiction
Wikipedia: Edgar Allan Poe