In the nick of time

1. Just in time. At the precise moment. Just before it is too late.

Because the ambulance arrived in the nick of time, the girl’s life was saved.

2. At the very last moment.

I was able to board the airplane in the nick of time.