Onan was a wicked man, the second son of Judah, grandson of Jacob, greatgrandson of Isaac, greatgreatgrandson of Abraham. His mother was Shua the Canaanite (Genesis 38:2,4; 1 Chronicles 2:3). His older brother, Er, was also wicked. (Judah had five sons—1 Chronicles 2:4.)
The biblical record says,
But Er, Judah's firstborn, was wicked in the Lord's sight; so the LORD put him to death. Then Judah said to Onan, “Lie with your brother's wife and fulfill your duty to her as a brother-in-law to produce offspring for your brother.” But Onan knew that the offspring would not be his; so whenever he lay with his brother's wife, he spilled his semen on the ground to keep from producing offspring for his brother. What he did was wicked in the Lord's sight; so he put him to death also. (Genesis 38:7-10, NIV)
Some have mistakenly assumed that Onan's sin was masturbation. However, it seems clear that this is not the case. Onan was prematurely withdrawing from sexual intercourse with his new wife, Tamar. This is a form of birth control still practiced today (coitus interruptus). Onan had an obligation to provide his wife with a child, and his brother with an heir (Deuteronomy 25:5; Matthew 22:24). He was now the oldest son in a tribe that was supposed to be fruitful and multiply in fulfillment of God’s promise to Abraham. As the heir of Judah, he was destined to one day become the tribe's spiritual and moral leader. Onan's sin was in purposely disobeying his father, denying his wife the opportunity of conceiving the child that she wanted (and probably needed). There were strong cultural and practical reasons for her desire for children, especially a male heir. Onan enjoyed sex, but rebelliously prevented its natural and beautiful result, the conception of a child. He was selfish to the core, and showed disrespect for his brother, his wife, his father, and God.
God judged Onan not fit for his ultimate position as the leader of this especially important tribe of God’s chosen people, which was destined to be the line of King David, and ultimately of Mary and Joseph, the parents of Jesus. The tribe would one day become known as “the Jews.”