By the skin of your teeth
Narrowly; barely. Usually used in regard to a narrow escape from a disaster.
The phrase first appears in English in the Geneva Bible, 1560, in Job 19:20, which provides a literal translation of the original Hebrew:
"I haue escaped with the skinne of my tethe."
Teeth don't have skin, of course, so the writer may have been alluding to the teeth's surface or simply to a notional minute measure - something that might now be referred to, with less poetic imagery than the biblical version, as 'as small as the hairs on a gnat's bollock'.