By the skin of one`s teeth

Barely.

We arrived on time for the train by the skin of our teeth.