In 1947, Grace Murray Hopper was working on the Harvard University Mark II Aiken Relay Calculator (a primitive computer).

On the 9th of September, 1947, when the machine was experiencing problems, an investigation showed that there was a moth trapped between the points of Relay #70, in Panel F.

The operators removed the moth and affixed it to the log.
The word went out that they had “debugged” the machine and the term “debugging a computer program” was born.