Genesis 38:9

9 But Onan knew that the child wouldn't be his, so whenever he slept with his brother's widow he spilled his semen on the ground so he wouldn't produce a child for his brother.

Genesis 38:9 Meaning and Commentary

Genesis 38:9

And Onan knew that the seed should not be his
Should not be called a son of his, but a son of his brother Er; this is to be understood only of the firstborn; all the rest of the children born afterwards were reckoned the children of the real parent of them; this shows this was a custom in use in those times, and well known, and was not a peculiar case: and it came to pass, when he went in unto his brother's wife;
to cohabit with her, as man and wife, he having married her according to his father's direction: that he spilled [it] on the ground, lest he should give his seed to
his brother:
lest his brother's wife he had married should conceive by him, and bear a son that should be called his brother's, and inherit his estate; and this is the sin, which from him is called Onania, a sin condemned by the light of nature, as well as by the word of God, and very prejudicial to mankind, as well as displeasing to God, as follows:

Genesis 38:9 In-Context

7 But Judah's firstborn, Er, grievously offended God and God took his life.
8 So Judah told Onan, "Go and sleep with your brother's widow; it's the duty of a brother-in-law to keep your brother's line alive."
9 But Onan knew that the child wouldn't be his, so whenever he slept with his brother's widow he spilled his semen on the ground so he wouldn't produce a child for his brother.
10 God was much offended by what he did and also took his life.
11 So Judah stepped in and told his daughter-in-law Tamar, "Live as a widow at home with your father until my son Shelah grows up." He was worried that Shelah would also end up dead, just like his brothers. So Tamar went to live with her father.
Published by permission. Originally published by NavPress in English as THE MESSAGE: The Bible in Contemporary Language copyright 2002 by Eugene Peterson. All rights reserved.