Star-gazing nobility come from the east, expecting a ruler born recently to the Jews. This scares the paranoid Herod, which in turn upsets the whole capital of Jerusalem. The scribes know the Scriptures: He is to be born in Bethlehem. Herod sends the wise men as unwitting spies, but God intervenes, giving dreams to the wise men, and to Joseph, saving Jesus' life, sending Him to Egypt. This way, Hosea 11:1 was also fulfilled. Herod, realizing he was tricked, resolves to be rid of the possible threat anyway, and kills all boys under 2 in the region of Bethlehem. This fulfills another Scripture, from Jeremiah. Herod dies, Joseph's family returns to Israel, but bypasses Judah, where Archealeus is a threat, returning to Nazareth.
Going back to Nazareth, Joseph and Mary raised Jesus in the nurture and admonition of... the Lord. Already at 12, Jesus knew His Father's business, and was advanced in His understanding of the Scriptures.