Snape is intensely curious about where Remus Lupin goes each month. Sirius jokingly suggests that Snape follow Lupin through the passage beneath the Whomping Willow. James Potter, realizing that Snape would encounter a full-blown and very dangerous werewolf at the end of the passage, stops Snape from going through, thereby saving his life (PA18). Snape, much to his disgust, is indebted to James because of this, according to Dumbledore (PS17).
Timeline Notes
The timeline of this event is rather problematic. For years fans assumed that the werewolf prank occurred after the bullying scene "Snape's Worst Memory" (OP28), which happened during during O.W.L. exams in James and Lily's 5th year. 1976. It was widely believed that the prank happened during James and Sirius's 6th year and the fact that James rushed into the tunnel to save Snape showed that he had reformed as a bully, making him less of a "toerag" to Lily so she would date him, which is what Sirius and Lupin led Harry to believe (OP29).
But the timeline of events in Snape's memories during Deathly Hallows disproved that, because chronologically, Snape and Lily discussed the werewolf prank happening some time before Snape's Worst Memory (DH33).
In PA, Snape reminded Dumbledore that Sirius tried to kill him "at the age of sixteen" (PA21). While Sirius and Lupin led Harry to think James was 15 at the time of O.W.L. exams (OP29), the fact is that all the Marauders, Lily, and Snape were 16 years old by the end of 5th year. Recently, J.K. Rowling revealed that Sirius Black's birthday is the third of November (JKR:Tw), too late in the year to be born in 1960 like Snape, Lily, Remus and James and still start at Hogwarts in 1971, so he must have been born on November 3, 1959, and would have turned 16 just after Halloween in 1975. That means the werewolf prank had to happen after November 3, 1975, but before June 1976. It's probable the prank didn't occur until early 1976, closer to O.W.L. exams.