It’s a situation where something bad almost happened but did not.

promašiti cilj, ne postići cilj, promašiti za dlaku, jedva izbjeći nesreću