After the wise men were gone, an angel of the Lord appeared to Joseph in a dream. “Get up! Flee to Egypt with the child and his mother,” the angel said. “Stay there until I tell you to return, because Herod is going to search for the child to kill him.”
That night Joseph left for Egypt with the child and Mary, his mother,
and they stayed there until Herod’s death. This fulfilled what the Lord had spoken through the prophet: “I called my Son out of Egypt.”
References for Matthew 2:15
Herod was furious when he realized that the wise men had outwitted him. He sent soldiers to kill all the boys in and around Bethlehem who were two years old and under, based on the wise men’s report of the star’s first appearance.
Herod’s brutal action fulfilled what God had spoken through the prophet Jeremiah:
“A cry was heard in Ramah— weeping and great mourning. Rachel weeps for her children, refusing to be comforted, for they are dead.”
References for Matthew 2:18
When Herod died, an angel of the Lord appeared in a dream to Joseph in Egypt.
“Get up!” the angel said. “Take the child and his mother back to the land of Israel, because those who were trying to kill the child are dead.”
So Joseph got up and returned to the land of Israel with Jesus and his mother.
But when he learned that the new ruler of Judea was Herod’s son Archelaus, he was afraid to go there. Then, after being warned in a dream, he left for the region of Galilee.
So the family went and lived in a town called Nazareth. This fulfilled what the prophets had said: “He will be called a Nazarene.”