One cliche is "by the skin of my teeth".