in the nick of time

中高级 (B2) informal

Just before it was too late.

"The firefighters arrived in the nick of time to save the building."