According to Luke, however, Mary and Joseph were from Nazareth. They travel to Bethlehem because a census requires them to do so. While they are there Jesus is born in a manger. After his birth they wait for Mary to go through ritual purification, after which they travel to Jerusalem to sacrifice two birds at the temple. After the sacrifice they go home to Nazareth.
ANSWER: As always in the Bible, BOTH accounts are correct because they speak of two different time periods. A quality Harmony of the Gospels should be able to lay out the time sequence of Jesus' entire life based on the four Gospel accounts. Luke's account is the actual event of Christ's birth in the manger.
The time sequence from the birth of Jesus to him being taken to Nazareth is as follows. Joseph is of the lineage of King David, who was born in Bethlehem. The Romans in 5 B.C. require all those in Judea to return to their ancestral home so that they can be counted (it really was for assessing what the people owned for the purposes of TAXES). Because of this decree Mary and Joseph travel to Bethlehem. It is in the city that Christ is born in a manger (Luke 2:1 - 20).
On the eighth day after his birth he is circumcised according to the law of God (Luke 2:21).
Jesus is then brought to Jerusalem's temple, after forty days of purification required by God's law, to be presented before God. His parents make an offering to the temple of two young birds. It is also during their visit to the temple that a priest named Simeon, prophesied about his mission in life and blessed his parents (Luke 2:22 - 35).
Before Mary and Joseph leave the temple a woman named Anna, a widowed prophetess who lived in the house of God, blesses them as well (Luke 2:36 - 38).
Magi from the arrive in Jerusalem a YEAR or more after Jesus is born in order to ask Herod where he is living. Although Herod does not have a clue of where the Messiah was to be born he asks the priests and scribes if they knew. They tell Herod the Christ would be born in Bethlehem. After leaving Jerusalem the Magi follow the same "star" (angel) that brought them to Judea. When they arrive at the house (NOT a manger!) they see Mary and Jesus (Joseph at this time is NOT there!) and offer their gifts (Matthew 2:1 - 11).
After the wise men leave an angel tells Joseph, in a dream, to flee to Egypt because Herod wants to kill their child (Matthew 2:13 - 15).
Herod commands that, in Bethlehem and the surrounding area, all male children two years old and younger be put to death (Matthew 2:16 - 18).
After Herod dies an angel of the Lord again appears to Joseph in a dream and tells him it is safe to return to Israel. After arriving in Judea Joseph discovers Archelaus now reigns. Fearful of going back and living in Bethlehem, Joseph again has an angelic being instruct him to go to Nazareth (Matthew 2:19 - 23, Luke 2:39). Jesus will live in the city until the beginning of his public ministry, at which time he then moves to Capernaum.