Genesis 38:9

He, knowing that the sons to be born would not be his, when he entered to the wife of his brother, he spilled his seed on the ground, lest children should be born in his brother’s name

Other versions

King James Version

And Onan knew that the seed should not be his; and it came to pass, when he went in unto his brother's wife, that he spilled it on the ground, lest that he should give seed to his brother.

English Standard Version

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.

New International Version

But Onan knew that the offspring would not be his; so whenever he lay with his brother's wife, he spilled his semen on the ground to keep from producing offspring for his brother.