The first part of the Hail Mary prayer are the words of the archangel Gabriel when he announced the birth of Jesus to the Virgin Mary, an event often referred to as the Annunciation (Luke 1:28). It appeared in liturgies as early as the 6th century.
The second part of the prayer are the words of Elizabeth when she was visited by Mary about the sixth month of her pregnancy with St. John the Baptist, an event referred to as the Visitation (Luke 1:42). It was added by about 1000 ce, with the appositive Jesus added two centuries later, possibly by Pope Urban IV.