by the skin of one's teeth
Just barely, very narrowly, as in Doug passed the exam by the skin of his teeth. A related term appears in the Bible (Job 19:20), where Job says, "I am escaped with the skin of my teeth," presumably meaning he got away with nothing at all. Today the phrase using by is used most often to describe a narrow escape. [c. 1600] Also see squeak through.