in the nick of time
Also, just in time. At the last moment, as in The police arrived in the nick of time, or He got there just in time for dinner. The first term began life as in the nick and dates from the 1500s, when nick meant “the critical moment” (a meaning now obsolete). The second employs just in the sense of “precisely” or “closely,” a usage applied to time since the 1500s. Also see in time, def. 1.