Sorry to hear that fluffysaurus, and very glad that you found the strength to resist.
I have known moments like those, and I can appreciate how frightening they are. I can get almost flippant about my suicidal thoughts sometimes, as they can be so frequent, yet usually are so easily resisted; an unhealthy complacency sometimes, I fear. But, every now and then, one comes along which is so spontaneous that it nearly sneaks past my rational thinking, and it scares me witless. I think that the tendency to ruminate is a big part of the problem; I think it can program our subconscious to free-wheel with the pattern of thinking while we're distracted by another task.
I hope you can find some help to resolve some of the underlying fears that are leading to these thoughts, and maybe something to focus on to minimise the rumination in the mean-time.
_________________
When you are fighting an invisible monster, first throw a bucket of paint over it.