When Joseph found out about Mary’s pregnancy, he must not have believed that she was pregnant by the Holy Spirit but that she had been unfaithful to him. Even though they were engaged and not married, to break the relationship, Joseph would have had to divorce Mary. In fact, adultery in engagement was even punishable by death in some cases! Joseph did not want to disgrace Mary, so he planned to divorce her in private. This only needed two witnesses rather than going through the Jewish courts and no formal grounds needed to be given for the divorce.
But in a dream, an angel appeared to Joseph and told him to trust Mary. The angel also told Joseph that the child should be called Jesus. Having a vision in a dream from God was a sign of God’s approval, so this would have made Joseph pay attention and do what the angel had said!
We’re not told who the angel was, but it could well have been Gabriel, who is God’s chief messenger angel. If you’d like to know more about Gabriel, go to the section on whychristmas?com’s sister site whyangels?com about Gabriel. The Christmas Story