An angel warns Joseph in a dream to flee to Egypt because Herod is about to search for the child to destroy him Matthew 2:13. Joseph leaves by night and stays there until Herod dies Matthew 2:14–15.
After the visitors leave, Joseph receives a warning in a dream. He is told to get up, take the child and the child’s mother, and escape to Egypt, because Herod intends to hunt the child down and kill him. Joseph obeys immediately, traveling at night and staying in Egypt until Herod dies. This scene continues Matthew’s early narrative of the child’s threatened safety and God’s guidance through dreams. It follows the departure of the visitors (2:12) and sets up Herod’s violent reaction (2:16–18). The story moves quickly: warning, command, obedience, and a stated reason.
Matthew presents God guiding and protecting the child through a dream given to Joseph. The threat is explicit: Herod intends to find the child in order to kill him. Joseph’s response is immediate and practical—he leaves at night, takes the child and the child’s mother, and goes to Egypt.
A careful answer keeps the immediate passage, the book's argument, and the whole-Bible storyline together, so the question is answered in context instead of as a detached idea.
Start with Matthew 2:13, then read the surrounding section so the answer stays connected to the passage's flow.
13Now when they had departed, behold, an angel of the Lord appeared to Joseph in a dream, saying, "Arise and take the young child and his mother, and flee into Egypt, and stay there until I tell you, for Herod will seek the young child to destroy him."