Used before a verb phrase to indicate that something was on the verge of happening, often with a sense of narrowly avoiding an outcome. Frequently followed by ~するところだった or ~しそうになった.
もう少しで電車に乗り遅れるところだった。
I almost missed the train.
もう少しで忘れるところだった。
I nearly forgot.
Combination of もう (already) + 少し (a little) + で (particle indicating a state or condition). Literally 'with just a little more', it evolved into a set phrase meaning 'almost'.