Genesis 38:8-9

38:8 Then Judah said to Onan, “Have sexual relations with your brother’s wife and fulfill the duty of a brother-in-law to her so that you may raise up a descendant for your brother.” 38:9 But Onan knew that the child would not be considered his. So whenever he had sexual relations with his brother’s wife, he withdrew prematurely so as not to give his brother a descendant.