Genesis 38:9

New International Version Bible (NIV)
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.

Read Genesis 38:9 in other translations