Genesis 38:10 in the King James Version
And the thing which he did displeased the LORD: wherefore he slew him also.
Context
9 Onan knew that the offspring wouldn’t be his; and when he went in to his brother’s wife, he spilled his semen on the ground, lest he should give offspring to his brother.
10 The thing which he did was evil in the LORD’s sight, and he killed him also.
11 Then Judah said to Tamar, his daughter-in-law, “Remain a widow in your father’s house, until Shelah, my son, is grown up;” for he said, “Lest he also die, like his brothers.” Tamar went and lived in her father’s house.