After they were gone, an angel of the Lord suddenly appeared to Joseph in a dream, saying, "Get up! Take the child and His mother, flee to Egypt, and stay there until I tell you. For Herod is about to search for the child to destroy Him."
References for Matthew 2:13
So he got up, took the child and His mother during the night, and escaped to Egypt.
He stayed there until Herod's death, so that what was spoken by the Lord through the prophet might be fulfilled: Out of Egypt I called My Son.
References for Matthew 2:15
Then Herod, when he saw that he had been outwitted by the wise men, flew into a rage. He gave orders to massacre all the male children in and around Bethlehem who were two years old and under, in keeping with the time he had learned from the wise men.
References for Matthew 2:16
Then what was spoken through Jeremiah the prophet was fulfilled:
A voice was heard in Ramah, weeping, and great mourning, Rachel weeping for her children; and she refused to be consoled, because they were no more.
References for Matthew 2:18
After Herod died, an angel of the Lord suddenly appeared in a dream to Joseph in Egypt,
References for Matthew 2:19
saying, "Get up! Take the child and His mother and go to the land of Israel, because those who sought the child's life are dead."
So he got up, took the child and His mother, and entered the land of Israel.
But when he heard that Archelaus 6 was ruling over Judea in place of his father Herod, he was afraid to go there. And being warned in a dream, he withdrew to the region of Galilee.
References for Matthew 2:22
Then he went and settled in a town called Nazareth to fulfill what was spoken through the prophets, that He will be called a Nazarene.