Matthew 1:18-25, KJV: “18 Now the birth of Jesus Christ was on this wise: When as his mother Mary was espoused to Joseph, before they came together, she was found with child of the Holy Ghost. 19 Then Joseph her husband, being a just man, and not willing to make her a publick example, was minded to put her away privily. 20 But while he thought on these things, behold, the angel of the Lord appeared unto him in a dream, saying, Joseph, thou son of David, fear not to take unto thee Mary thy wife: for that which is conceived in her is of the Holy Ghost. 21 And she shall bring forth a son, and thou shalt call his name JESUS: for he shall save his people from their sins. 22 Now all this was done, that it might be fulfilled which was spoken of the Lord by the prophet, saying, 23 Behold, a virgin shall be with child, and shall bring forth a son, And they shall call his name Emmanuel, which being interpreted is, God with us. 24 Then Joseph being raised from sleep did as the angel of the Lord had bidden him, and took unto him his wife: 25 and knew her not till she had brought forth her firstborn son: and he called his name JESUS.”
When Mary came back from seeing Elisabeth and her family, Joseph (and the rest of the town) would have noticed soon after that she was pregnant.
Joseph didn't want her stoned, which was the general punishment, based on Jewish law, for being pregnant without being married (and if they found the man as well, he was also stoned). He would have just divorced her secretly (remember, their version of engagment was very similar to marriage).
An angel came to Joseph in a dream and told him also what the Angel Gabriel told Mary. Joseph was a man of faith, so he listened to what the angel said and did it. However, what he didn't know was that the story was going to take a large twist (but in order to fulfill prophecy, as Jesus wasn't to be born in Nazareth).
What was that twist? We'll get to find out onMonday, December 13. Keep in mind that it has to do with government regulation (just like what we see now). Can God even use governments to accomplish His will?