cut it close
idiom
variants:
or chiefly British cut it fine
Definition of cut it close
: to almost not be able to do something : to almost fail, lose, etc.
They ended up winning the game, but they really cut it close at the end It's cutting it a bit fine to get to the station at 9:45 when the train leaves at 9:50!