Used when a negative outcome was narrowly avoided; often followed by ところだった or a negative verb form.
I almost missed the train.
彼は危うく事故に遭うところだった。
He narrowly avoided an accident.
Indicates that something came close to happening, often with a sense of relief that it did not; similar to もう少しで.
危うく忘れるところだった。
I almost forgot.
I nearly missed the train.
I almost fell over.