The poem was inspired by a real event when Mary's pet lamb followed her to school. Later, John Roulstone, a young man visiting the school, wrote the initial verses about the incident. Sarah Josepha Hale added more verses, and together, these contributions formed the beloved nursery rhyme we know today.