The phrase “in the nick of time” means, of course, at the critical or precise moment; just at the instant when our hero was saved at the last moment from onrushing death, for example.
The expression is about three centuries old, formed when someone added the redundant “of time” to the older expression, “in the nick,” which meant the same thing.
A nick is a groove, a notch, as made with a sharp knife when one cuts a V in a stick of wood. Nothing could express precision more accurately than a notch so formed, especially when applied to time.