According to Matthew, Joseph sought refuge from Herod the Great in Egypt (Matthew 2:13-15).
Matthew attempts to justify his fabrication with the following unwarranted trim of Hosea 11:1-2,
When Israel was a child, I loved him, and out of Egypt I called my son. But the more I called Israel, the further they went from me. They sacrificed to the Baals and they burned incense to images.(Hosea 11:1-2)
Golden Rule: If an intended Old Testament justification is fraudulent, the New Testament anecdote is a fabrication.
Aside for the thoughtful reader
Anybody hounded by Herod the Great would not be safe in Egypt because the Edomite king had the ear of Caesar Augustus,
Now when Herod the Great had reigned seventeen years Caesar came to Syria and gave him Zenodorus' country, made him a procurator of Syria and bid the others do everything with Herod's approval. In short, Herod arrived at that pitch of felicity where although two men governed the vast Roman empire, first Caesar and then Agrippa, Caesar preferred no one to Herod besides Agrippa, and Agrippa no one to Herod besides Caesar.(Antiquities of the Jews. Book XV, Chapter 10, par. 3. Edited)
Rumour had it that Augustus and Agrippa said often that the dominions of Herod were too small for the greatness of his soul and that he deserved to have both Syria and Egypt also (Ibid., Book XVI, Chapter 5, par. 1).