King Herod, hearing that a new born King had been born in Bethlehem, was threatened. So he ordered all boys in the region, two years and under, killed.
An angel appears to Joseph, warning him of the King's edict. Mary and Joseph flee into Egypt. They are forced to leave their home and families -- everything dear to them, in order to protect Jesus. Tradition holds that the Holy Family went to Fostat, not far from Cairo, about 300 miles from Bethlehem. In fact, there is a Church there today which commemorates this event.
Mary and Joseph would stay in Egypt until the death of King Herod, whereupon they would return to make their home in Nazareth.