Jaehaerys, Aerys' father, had dealings with Jenny of Oldstones (a.k.a. "The Ghost of High Heart" in one of the Arya chapters), a prophet of sorts who said that the prince that was promised would come from his line. As such, he commanded his son Aerys and his daughter Rhaella to marry in order to produce that "prince". Then Rhaegar was born in the same day of the Summerhall tragedy, which as mentioned, impacted him for all his life. Barristan said that he had a sort of sadness about him because of that. For a while, he thought he was the "prince", but then he realized it would be one of his children. Somewhere along the line ( I don't remember if that was part of the prophecy), came the idea that "the dragon must have three heads" and Rhaegar interpreted it to mean that he had to have three children. Elia Martell, however, was weak of health and could only give him two. So it is implied that he wanted Lyanna to bear his third. That being why he seduced and "kidnapped" Lyanna, which sparked the Rebellion.
Later on, the "prince" prophecy got a little bit conflated with the Azor Ahai one. I don't remember if Melisandre believed in the "prince" theory, but Maester Aemon would later realize that the High Valyrian word for "prince" is neutral and could mean male or female, and came to believe that Daenerys was that "prince". It makes sense, as Dany is of Jaeherys' line, but then again, so is Jon, if R+L=J is true in the books.
EDIT: My bad, Jenny and The Ghost are two different people, but it seems it was Jenny who introduced Jaeherys and the Ghost.