The story
First attested in a collection of proverbs by John Heywood in 1546, in the form “Treade a worme on the tayle, and it must turne agayne.” Popularized by William Shakespeare in The Third Part of Henry the Sixth, see quotations.
Etymology from Wiktionary, CC BY-SA 4.0.