Now when they had departed, behold, an angel of the Lord appeared to Joseph in a dream, saying, "Arise, take the young Child and His mother, flee to Egypt, and stay there until I bring you word; for Herod will seek the young Child to destroy Him."
When he arose, he took the young Child and His mother by night and departed for Egypt,
and was there until the death of Herod, that it might be fulfilled which was spoken by the Lord through the prophet, saying, "Out of Egypt I called My Son."
References for Matthew 2:15
Then Herod, when he saw that he was deceived by the wise men, was exceedingly angry; and he sent forth and put to death all the male children who were in Bethlehem and in all its districts, from two years old and under, according to the time which he had determined from the wise men.
Then was fulfilled what was spoken by Jeremiah the prophet, saying:
"A voice was heard in Ramah, Lamentation, weeping, and great mourning, Rachel weeping for her children, Refusing to be comforted, Because they are no more."
References for Matthew 2:18
But when Herod was dead, behold, an angel of the Lord appeared in a dream to Joseph in Egypt,
saying, "Arise, take the young Child and His mother, and go to the land of Israel, for those who sought the young Child's life are dead."
Then he arose, took the young Child and His mother, and came into the land of Israel.
But when he heard that Archelaus was reigning over Judea instead of his father Herod, he was afraid to go there. And being warned by God in a dream, he turned aside into the region of Galilee.
And he came and dwelt in a city called Nazareth, that it might be fulfilled which was spoken by the prophets, "He shall be called a Nazarene."