A funnier and more extreme version of "By the skin of my teeth". Emphasizing a very close shave or a very narrow escape from danger.
"Phew, that was close. I literally survived that by the foreskin on my dick."