7But Er, Judah’s firstborn, was wicked in the sight of the LORD; so the LORD put him to death.
8Then Judah said to Onan, “Sleep with your brother’s wife. Perform your duty as her brother-in-law and raise up offspring for your brother.”
9But Onan knew that the offspring would not belong to him; so whenever he would sleep with his brother’s wife, he would spill his seed on the ground so that he would not produce offspring for his brother.
10What he did was wicked in the sight of the LORD, so He put Onan to death as well.
— Genesis 38:7-10