The informal and very common expression salvarse por los pelos, or also salvarse por un pelo, currently means to survive or escape alive from an imminent danger in the nick of time "by a stroke of luck," or to put it another way "por los pelos." In English, these meaning is conveyed by the expressions by the skin of one's teeth or by a hair's breadth.
Se salvó por los pelos de morir electrocutado en la silla eléctrica.
He escaped alive from being electrocuted in the electric chair.
Se salvó por los pelos de morir electrocutado en la silla eléctrica.
He escaped alive from being electrocuted in the electric chair.