Actually, we owe the first half of it to the angel Gabriel and to Mary’s cousin Elizabeth. “Hail, full of grace, the Lord is with thee,” are the words of the angel when he greets Mary at the Annunciation (Luke 1:28). During the visitation, Mary’s cousin Elizabeth welcomes her with the words, “Blessed are you among women, and blessed is the fruit of your womb.” (Luke 1:42). The joining of the two salutations in prayer appears to have become a widespread practice in the mid-eleventh century, though there is evidence of it showing up in eastern rites as far back as the sixth century.
The second part of the “Hail Mary” is where we ask for Mary’s intercession: “Holy Mary, Mother of God, pray for us sinners, now and at the hour of our death.” Various forms of this go back to the fourteenth century; the wording as we use it today became official in 1568.
So in answer to your question, it’s fair to say that the Hail Mary prayer evolved out of Scripture, as well as the lived reflection of the Church in the centuries that followed. Its popularity is a testament to the continuing appeal of Mary as a helper and guide. If we want a heavenly intercessor on our side, who is better than Mary, the mother who has a personal interest in seeing her son’s work continue? As the Catechism says, “We can pray with and to [Mary]. The prayer of the Church is sustained by the prayer of Mary and united with it in hope.” (CCC2679)