A
practice named after
Onan in the
Old Testament, who was commanded by
God to impregnate his
brother's
widow so that there would be an
heir for his brother's line. Onan had sex with the
woman, but pulled out and "spilled his seed upon the ground," thereby incurring God's
wrath.
The word came to mean masturbation because in many branches of Christian theology, any act that involved sperm being wasted was pretty much the same sin.