The book of Job in the Bible, at Chapter 19 verse 20, has Job talking about the devastating effects illness has brought on him. He says: "My bone cleaveth to my skin and to my flesh and I am escaped with the skin of my teeth." Clearly, he is so emaciated that he has become almost skeletal and he feels that there is virtually nothing left of his body but the skin on his teeth. Of course, teeth do not have �skin' as such, so it presumably refers either to their surface enamel or the gums.
It was not until the 19th century that the phrase changed slightly to �by - rather than �with' - the skin of my teeth' and took on the suggestion of the narrowest of margins or escapes.