According to the text, after God had killed Onan's older brother Er, Judah asked Onan to have sex with Tamar, Er's widow, so that the offspring could be declared Er's heir. The narrative implies that Onan didn't object to the sex itself, but performed coitus interruptus, spilling his seed upon the ground, so that there wouldn't be any offspring which he could claim as his own. The passage then goes on to state that, for this act, a displeased God killed him. The deaths of Onan and Er are among the few deaths caused by God which the Torah doesn't describe as being caused via an intermediary, such as plague, or the Angel of Death.
According to some biblical scholars who contextually read this passage, the description of Onan is an eponymous aetiological myth concerning fluctuations in the constituency of the tribe of Judah, with the death of Onan reflecting the dying out of a clan; Er and Onan are hence viewed as each being representative of a clan, with Onan possibly representing an Edomite clan named Onam, mentioned by an Edomite genealogy in Genesis.
The text emphasises the social and legal situation, with Judah explaining what Onan must do and why; the plain reading of the text is that Onan was killed because he refused to follow instructions. Scholars have argued that the secondary purpose of the Tamar narrative, of which the description of Onan is a part, was to either assert the institution of levirate marriage, or present an aetiological myth for its origin; Onan's role in the narrative is, thus, as the brother abusing his obligations by agreeing to sexual involvement with his dead brother's wife, but refusing to allow her to become pregnant as a result. Emerton regards the evidence for this as inconclusive, although classical rabbinical writers argued that this narrative describes the origin of levirate marriage.
However, other early writers focused on the spilling seed, and the sexual act being used for non-procreational purposes; one opinion expressed in the Talmud argues that this was where the death penalty's imposition originated. This interpretation was held by several early Christian apologists; Jerome, for example, arguing:
But I wonder why he the heretic Jovinianus set Judah and Tamar before us for an example, unless perchance even harlots give him pleasure; or Onan, who was slain because he grudged his brother seed. Does he imagine that we approve of any sexual intercourse except for [br]the procreation of children?
Clement of Alexandria, while not making explicit reference to Onan, similarly reflects an early Christian view of the abhorrence of '"spilling seed'":
Because of its divine institution for the propagation of man, the seed is not to be vainly ejaculated, nor is it to be damaged, nor is it to be wasted
Many Christian groups, especially Roman Catholicism, have subsequently cited the Onan narrative as justification for bans on both masturbation and coitus interruptus, and, since medieval times, have also used it to justify a prohibition against contraception. This view - that wasted seed refers to masturbation - was upheld by many early rabbis. However, the Levitical regulations concerning ejaculation, whether as a result of heterosexual intercourse or of masturbation or nocturnal emission, merely prescribe a ritual washing, and remaining ritually impure until the next day began on the following evening.
Robert Jordan, the main character in Ernest Hemingway's book "For Whom the Bell Tolls", also makes reference to Onan, the night before he is due to fight in battle: "He smiled and thought: "I'll keep any oversupply of that for tomorrow. I'll need all of that there is tomorrow. There are no pine needles that need that now as I will need it tomorrow. Who was it cast his seed upon the ground in the Bible? Onan. How did Onan turn out?" he thought. "I don't remember ever hearing any more about Onan". He smiled in the dark."