Onan (Hebrew: אוֹנָן, Modern Onan, Tiberian ʼÔnān; "Strong") is a minor biblical person in the Book of Genesis chapter 38, who was the second son of Judah. Like his older brother Er, Onan was slain by God. Onan's death was retribution for being "evil in the sight of the Lord" through being unwilling to father a child by his widowed sister-in-law.
After Onan's brother Er died, his father Judah told him to fulfill his duty to his brother by entering into a levirate marriage with his brother's widow Tamar to give her offspring. Religion professor Tikva Frymer-Kensky has pointed out the economic repercussions of a levirate marriage: any son born to Tamar would be deemed the heir of the deceased Er, and able to claim the firstborn's double share of inheritance. However, if Er were childless, Onan would have inherited as the oldest surviving son.
When Onan had sex with Tamar, he withdrew before his orgasm and "spilled his seed [or semen] on the ground", since any child born would not legally be considered his heir. The next statement in the Bible says that Onan did evil and that God slew him.
The implication from the narrative is that Onan's act as described is what gave rise to divine displeasure, but even if that is the case it is not clear whether his objectionable behaviour was the refusal to complete the levirate obligation of providing sperm for his brother's widow to continue his brother's name (and clan rights) or "shedding seed in vain", or even having sex with Tamar (who would normally be prohibited to him as a sister-in-law) outside the context of an overriding levirate obligation.