Genesis 38 interrupts the account of Joseph to discuss Judah and his family.
After moving away from his brothers, Judah married a Canaanite woman and had three sons: Er, Onan, and Shelah. Judah arranged for his firstborn Er to marry a woman named Tamar, but Er was “wicked in the sight of the LORD; and the Lord slew him” before Er could produce an heir.
Following custom, Judah instructed his second son Onan to fulfill the duty of a brother-in-law by marrying Tamar and providing children for his dead brother. However, Onan, knowing that any child born would not be considered his own, deliberately spilled his seed on the ground during intercourse. This displeased God, who put Onan to death as well.
Judah then promised Tamar that his third son Shelah would marry her when he grew up. But, afraid that Shelah also might die, Judah delayed fulfilling this promise and sent Tamar back to her father’s house to wait. As time passed, Tamar realized Judah had no intention of giving her to Shelah, even though Shelah had now grown up.
When Tamar learned that Judah was traveling to shear his sheep, she removed her widow’s clothes, covered herself with a veil, and sat in an open place “by the way to Timnath.” Judah, not recognizing her, mistook her for a prostitute and propositioned her. She agreed on the condition that he give her his signet, bracelets, and staff as a pledge until he sent payment of a young goat. After their encounter, Tamar went back home and put her widow’s garments back on.
When Judah sent a friend to deliver the promised goat and retrieve his personal items, the woman couldn't be found. About three months later, Judah learned that Tamar was pregnant through prostitution. He angrily ordered that she be brought out and burned. As she was being brought out, Tamar produced Judah’s signet, bracelets, and staff, saying, “By the man, whose these are, am I with child.”
Judah recognized his items and acknowledged that Tamar was more righteous than he was, as he failed to give her to his son Shelah as promised. Judah didn't sleep with her again.
When the time came for Tamar to give birth, she delivered twins. During the delivery, one twin (Zarah) put out his hand first, and the midwife tied a scarlet thread around it. But, he drew back his hand, and his brother (Pharez) came out first.