Onan [Genesis 38:6-10] was ordered by his dad, Judah, to sleep with and impregnate his late brother's former wife - as was the Jewish law at the time.
For some reason (which may have been due to the ickiness of the whole set up) he did not impregnate her (coitus interruptus) instead, spilling his semen on the ground.
For refusing to honour his legal duty to impregnate his sister-in-law, God (somewhat harshly, it seems to me) put him to death.
This passage has been used as a reason to frown upon masturbation (if you know what I mean) whereas, in fact, the Bible is silent on the issue.
Presumably because the prophet who was to write on the subject had already been struck blind.