The invention of the term is often erroneously attributed to Grace Hopper, who publicized the cause of a malfunction in an early electromechanical computer. A typical version of the story is given by this quote:
In 1946, when Hopper was released from active duty, she joined the Harvard Faculty at the Computation Laboratory where she continued her work on the Mark II and Mark III. Operators traced an error in the Mark II to a moth trapped in arelay, coining the term bug. This bug was carefully removed and taped to the log book September 9th 1945. Stemming from the first bug, today we call errors or glitch’s [sic] in a program a bug.
For the actual story see http://en.wikipedia.org/wiki/Computer_bug