8 Then Judah said to Onan, “Sleep with your brother’s wife and fulfill your duty to her as a brother-in-law to raise up offspring for your brother.” 9 But Onan knew that the child would not be his; so whenever he slept with his brother’s wife, he spilled his semen on the ground to keep from providing offspring for his brother. 10 What he did was wicked in the Lord’s sight; so the Lord put him to death also.
Genesis 38:8 - 10
ESV - 8 Then Judah said to Onan, "Go in to your brother's wife and perform the duty of a brother-in-law to her, and raise up offspring for your brother. 9 But Onan knew that the offspring would not be his. So whenever he went in to his brother's wife he would waste the semen on the ground, so as not to give offspring to his brother.
For follow-up discussion and general commentary on the topic. Comments are sorted chronologically.