As a child, Jiraiya and his former team-mates, Orochimaru and Tsunade, were students of the Third Hokage. Jiraiya's relation with his team practically mirrored that of the future Team 7, with Jiraiya being quite similar to Naruto. After leaving the Third's tutelage, he travelled the world.
Jiraiya at some point discovered the residence of the toads, a species he proved to have a natural affinity for. In the anime this is shown to have occurred when he was still the Third's student; after seeing the Third perform the Summoning Technique, Jiraiya tried to use it himself. Since he did not have a contract, Jiraiya was reversed summoned to Mount Myōboku, where the Great Toad Sage made a prophecy concerning Jiraiya: that he would someday choose whether one of his students saved or destroyed the world. During his time with the toads, he trained in senjutsu.
During the Second Shinobi World War, Jiraiya and his former team-mates fought Hanzō, the leader of Amegakure. Hanzō was so impressed that they could survive in a fight with him, that he bestowed upon them the title of Konoha's "Legendary Three Ninja" (伝説の三忍, Densetsu no Sannin), and that they accept the title in exchange for letting them live. Once the battle was over, Jiraiya and his team-mates encountered three young orphans from Amegakure. While Orochimaru suggested they kill them to spare them the cruelty of the world, Jiraiya decided to look after them for a while and teach them ninjutsu. During the time he spent with them, Jiraiya grew close to the three children, and even wrote a book that was inspired by one of them, Nagato. Eventually, he left them so that they could pursue their own goals. Although news of their exploits reached him from time to time, he thought them to have died during an undisclosed incident
Once becoming a jōnin and capable of leading a squad, Jiraiya became the teacher of Minato Namikaze and two other unknown genin. Jiraiya took special interest in Minato, taking him as an apprentice, and amongst other things teaching him the Summoning Technique. At some point, he also told Minato about the prophecy the Great Toad Sage had given him, believing that Minato could be the Child of the Prophecy.
Later, Jiraiya's first book, The Tale of the Utterly Gutsy Shinobi, failed to be a best-seller. Minato, now the Fourth Hokage, thought the book was excellent, and praised Jiraiya, saying that the protagonist resembled him greatly. It was then that Minato revealed that he and Kushina Uzumaki, who was pregnant at the time, wanted to raise their child to be a great shinobi, like the one in the book, and for that reason they decided to name him "Naruto", after the main character. Jiraiya jokingly pointed out that it would make him Naruto's godfather, and asked if they were sure that they would want that. Minato replied that Jiraiya was a good example for them all and that he could not think of a finer shinobi than him. 
Years later, when Orochimaru betrayed Konoha and left the village, Jiraiya pursued him, trying to convince his friend to come back (similar to Naruto's efforts to bring Sasuke home). Orochimaru refused, and attacked Jiraiya. While he tried to find a reason for Orochimaru's defection, Jiraiya eventually realised that his friend wasn't coming back. Feeling that he was responsible for Orochimaru's escape, Jiraiya left Konoha so he could follow Orochimaru's movements, as well as those of "Akatsuki", an organisation which Orochimaru had eventually joined. In doing so, Jiraiya was unable to fulfil the Third's wishes of him taking on the role of Hokage, feeling that tracking down Orochimaru was more important.
Jiraiya first met Naruto Uzumaki while he was "researching" at the hot springs in Konoha. After Jiraiya knocked out Ebisu for catching him in the act, Naruto demanded that Jiraiya begin training him in Ebisu's place. He refused, until Naruto used his Sexy Technique. When they started training, Jiraiya removed Orochimaru's Five Elements Seal from Naruto's stomach, which allowed him to tap into the Nine-Tailed Demon Fox's chakra. To teach him how to take advantage of the Nine-Tails' reserves, Jiraiya taught Naruto how to use the Summoning Technique, but was met with very poor results. To this end, Jiraiya decided to force Naruto to use the Nine-Tails' chakra by pushing him off a cliff. Naruto survived by summoning Gamabunta.
When Orochimaru began his invasion of Konoha, Jiraiya summoned Gamahiro to stop Orochimaru's snakes. He later mourned the Third Hokage's death, but decided not to attend the funeral.
With the Third's death, the village elders, Homura Mitokado and Koharu Utatane, requested that Jiraiya become the next Hokage, which he quickly turned down. Instead, he volunteered to search for his former team-mate, Tsunade, asking only that he be allowed to take Naruto with him.
Just a day after setting off, however, Itachi Uchiha and Kisame Hoshigaki of Akatsuki tried to kidnap Naruto. To do so, they used genjutsu on a woman to distract Jiraiya while they captured Naruto. Jiraiya saw through the trick, and intercepted Itachi and Kisame, who decided they did not want to get involved in a fight with one of the Sannin. When they tried to escape, Jiraiya used Summoning: Toad Mouth Bind to trap Itachi and Kisame. Nobody had ever managed to escape that technique before, but Itachi used Amaterasu to burn through the walls and escaped. After that, Naruto and Jiraiya resumed their search for Tsunade, Jiraiya teaching Naruto the Rasengan along the way to keep him occupied
Orochimaru found Tsunade before Jiraiya did, and asked that she heal his arms. When Jiraiya eventually found her as well, he suspected that they were in contact, and threatened Tsunade not to help Orochimaru. In response, Tsunade drugged his sake when they went to a bar, making it difficult for him to move or use chakra. After he discovered that this was so he wouldn't interfere in her attempt to kill Orochimaru, Jiraiya came to help her. In his drugged state, he struggled to fight Orochimaru, but was able to recover to the point that he could summon Gamabunta to fight Orochimaru's Manda. The healthy Tsunade proved too much for Orochimaru and Manda, defeating the two and causing them to flee. Tsunade then accepted her post as the Fifth Hokage, and they returned to Konoha.
After taking Naruto back to Konoha, Jiraiya went off to search for information on Akatsuki. Jiraiya would soon return to inform Kakashi and Yamato about Naruto's four-tailed form, a form so powerful that it nearly killed Jiraiya before he managed to stop it. It was later revealed that Jiraiya himself released it (not expecting Naruto's loss of control) with a special key passed down from the Fourth Hokage, capable of unlocking Naruto's seal.
In the anime, Jiraiya returned to Konoha to congratulate Naruto on defeating Akatsuki's Kakuzu and Deidara. In order to keep Naruto from participating in Team 7's new Sasuke-related mission, Jiraiya offered to train him again, and took Naruto to Yugakure. Jiraiya and Naruto also had a discussion over the meaning of 'home': "Wherever someone is thinking of you, that is the place you can return to." In light of Naruto's need to learn some high-ranked, long-distance techniques, Jiraiya introduced Naruto to the concept of synchronised, collaboration jutsu and began by demonstrating a synchronising jutsu, the Water Release: Water Gun technique, in collaboration with Gamariki.
When Naruto and Gamariki proved unable to synchronise, due to their conflicting personalities, Jiraiya confronted Naruto with the fact that, unless he can work with a summoned toad, a collaboration jutsu would stay out of his reach. Naruto compensated by summoning toads that he did get along with, and, after giving up on trying to work with Gamariki, finally began on working with a synchronised jutsu with Gamatatsu, while Gamakichi guided the process.
Jiraiya openly applauded Naruto's progress, and expressed how pleased he was at his dedication to his goals and beliefs. After receiving a message about Akatsuki, Jiraiya was forced to leave Naruto to continue training by himself, though not before convincing Tsunade to let Naruto go on the mission.
Jiraiya and Naruto have left Konoha to begin their three-year journey. As they walk, they talk about Naruto's need to overcome Sasuke's Sharingan. During a genjutsu practice, Naruto tries to disrupt his inner chakra flow, but instead, creates a wave of chakra around him thus hitting Gamariki in the physical world. To overcome this part of the training, Jiraiya takes Naruto to the Genjutsu Tree Village. After realising that the village was taken over by a man named Kandachi, Naruto and Jiraiya decide to liberate the village. As the final battle with Kandachi continued, Jiraiya and Naruto got trapped in the Conch King's Water Release Genjutsu: Mystic Fog Prison but later managed to escape thanks to Tanishi's Chilli Pepper Bomb. At the end of the battle, Naruto defeats Kandachi with his Great Ball Rasengan.
After learning about the defeat of Orochimaru at the hands of Sasuke, Jiraiya informed Tsunade that he had found the location of the Akatsuki leader, somewhere in Amegakure. After a chat with Tsunade, revealing much of Naruto's history, amongst others who his parents were, he left to infiltrate Amegakure and see what he could find out. He captured two Rain villagers while there, and sent one to Konoha to be interrogated. After hearing that the Akatsuki leader, Pain, killed Hanzō in battle, Jiraiya decided to leave the key to the Nine-Tails' seal to Naruto, before going out to see what else he could learn.
Jiraiya eventually found Konan, and after incapacitating her with his oil, questioned what happened to her, Yahiko, and Nagato. Suddenly Pain appeared and Jiraiya recognised him as his former student, Nagato, because of his Rinnegan. Fearing that his student would destroy the world, as was warned against in the prophecy, Jiraiya tried to kill Pain. After summoning Gamaken to protect him from various summons, he entered Sage Mode, and summoned Shima and Fukasaku to help him, but had difficulty with the battle when Pain summoned additional bodies (the Preta Path and the Human Path). Although they were able to defeat three of Pain's bodies with a powerful genjutsu, Jiraiya was handicapped when Pain's Asura Path ambushed Jiraiya and somehow severed his left arm. The Asura Path was joined by the other five paths, with the first three having been reanimated. Doing the most that he could, Jiraiya managed to kill and capture the Animal Path, and ordered Shima to take it to Konoha, before heading out one last time to see if he could figure out the secret behind Pain.