Barely or narrowly — just avoiding something bad (used like 'I barely...').
危うく電車に乗り遅れるところだった。
I almost missed the train.
歩行者が飛び出してきて、危うく車にぶつかるところだった。
A pedestrian ran out, and I barely avoided hitting them with the car.
危うく宿題を忘れるところだったが、かろうじて思い出した。
I almost forgot my homework, but I barely remembered it in time.
Almost; nearly — indicating that something was on the verge of happening.
危うく全部忘れるところだった。
I nearly forgot everything.
危うく彼女に気づかれそうになったが、そっとその場を離れた。
I was almost noticed by her, but I quietly left the place.
危うく成功しそうだったが、最後に失敗してしまった。
We were almost successful, but in the end we failed.