And having been warned in a dream not to return to Herod, they left for their own country by another road.
Now after they had left, an angel of the Lord appeared to Joseph in a dream and said, "Get up, take the child and his mother, and flee to Egypt, and remain there until I tell you; for Herod is about to search for the child, to destroy him."
Then Joseph got up, took the child and his mother by night, and went to Egypt,
References for Matthew 2:14
and remained there until the death of Herod. This was to fulfill what had been spoken by the Lord through the prophet, "Out of Egypt I have called my son."
When Herod saw that he had been tricked by the wise men, he was infuriated, and he sent and killed all the children in and around Bethlehem who were two years old or under, according to the time that he had learned from the wise men.
References for Matthew 2:16
Then was fulfilled what had been spoken through the prophet Jeremiah:
"A voice was heard in Ramah, wailing and loud lamentation, Rachel weeping for her children; she refused to be consoled, because they are no more."
When Herod died, an angel of the Lord suddenly appeared in a dream to Joseph in Egypt and said,
"Get up, take the child and his mother, and go to the land of Israel, for those who were seeking the child's life are dead."
Then Joseph got up, took the child and his mother, and went to the land of Israel.
References for Matthew 2:21
But when he heard that Archelaus was ruling over Judea in place of his father Herod, he was afraid to go there. And after being warned in a dream, he went away to the district of Galilee.