9-10 Onan did as he was told, but while doing so, he spilled his seed on the ground, so God killed him too.
11 After God killed her husband (Er) and his brother (Onan), Judah said to his daughter-in-law, Tamar,
Remain a widow in your father's house until my son Shelah is old enough to have sex with you.
It'd be a shame if he also died before impregnating you.
12 Later, when Judah's wife died, he went to Timnath to sheer his sheep.
Judah and Tamar
12-14 When Tamar heard that her father-in-law was in Timnath, she took off her widow's garments, covered herself with a veil, and sat in an open place on the way to Timnath.
15 When Judah saw her, he thought she was a harlot, because she had covered her face. 16 So Judah said,
Let me have sex with you. (He didn't know she was his daughter-in-law.)
And she said, "What will you give me to have sex with you?"
The Bible says that if a man dies, his brother must have sex with his dead brother's wife. (Dt 25:5-10)
So when God killed Er, it was his younger brother Onan's job to impregnate Er's wife, Tamar.
And when God killed Onan (for spilling his seed when he was supposed to be using it to impregnate his dead brother's wife), it was his younger brother Shelah's job to get the job done.
When Shelah didn't do it, Tamar decided to get someone else to. That someone else was her father-in-law Judah.
Onan spilled his seed on the ground. (v.9)
This lovely Bible story is seldom read in Sunday School, but it is the basis of many Christian doctrines, including the condemnation of masturbation, homosexuality, and birth control.
Judah finally acknowledges that he has done something wrong. Though it wasn't that he had sex with his daughter-in-law, Tamar; it was that he didn't force his third (and only surviving son) to impregnate her.
Pharez and Zarah (vv.29-30)
From this incestuous union, twins were born (both were boys of course).
One of these was Pharez -- an ancestor of Jesus (Mt 1:3, Luke 3:33).