According to Joseph Bigler, the quotation first came from a certain Robert J. Hanlon as a submission for a book compilation of various jokes related to Murphy's law published in 1980 entitled Murphy's Law Book Two, More Reasons Why Things Go Wrong.
A similar quotation appears in Robert A. Heinlein's 1941 short story "Logic of Empire" ("You have attributed conditions to villainy that simply result from stupidity"); this was noticed in 1996 (five years before Bigler identified the Robert J. Hanlon citation) and first referenced in version 4.0.0 of the Jargon File, with speculation that Hanlon's Razor might be a corruption of "Heinlein's Razor". "Heinlein's Razor" has since been defined as variations on Never attribute to malice that which can be adequately explained by stupidity, but don't rule out malice. or ... but keep your eyes open. A variant, Grey's Law (influenced, no doubt, by Clarke's third law), posits "Any sufficiently advanced incompetence is indistinguishable from malice."
Observations on the sway of human error over malice occur in various works. Goethe's The Sorrows of Young Werther (1774) mentions "...misunderstandings and neglect create more confusion in this world than trickery and malice. At any rate, the last two are certainly much less frequent." A probably apocryphal quote from Albert Einstein deals with the power of stupidity: "Only two things are infinite, the universe and human stupidity, and I'm not sure about the universe." Compare Schiller's "Against stupidity, the gods themselves contend in vain." Asimov's novel The Gods Themselves was named after Schiller's quote. Similarly, Elbert Hubbard said, "Genius may have its limitations, but stupidity is not thus handicapped."[citations needed]
A similar epigram has been widely attributed to Napoleon Bonaparte ("Never ascribe to malice that which is adequately explained by incompetence."). It is also attributed to William James among others.
A practical observation on the risks of stupidity was made by the German General Kurt von Hammerstein-Equord in Truppenführung, 1933: "I divide my officers into four classes; the clever, the lazy, the industrious, and the stupid. Each officer possesses at least two of these qualities. Those who are clever and industrious are fitted for the highest staff appointments. Use can be made of those who are stupid and lazy. The man who is clever and lazy however is for the very highest command; he has the temperament and nerves to deal with all situations. But whoever is stupid and industrious is a menace and must be removed immediately!"
A common (and more laconic) British English version, coined by Sir Bernard Ingham, is the saying "Cock-up before conspiracy". The full quotation given by Sir Bernard is "Many journalists have fallen for the conspiracy theory of government. I do assure you that they would produce more accurate work if they adhered to the cock-up theory."