I don't think you can just 'stop' them, but the therapy should help to do reduce them greatly if done properly. I am having CBT and doing that well to be honest but plodding on.
The irony is that the treatment is to seek out the thoughts. The reason they keep coming into your/my heads is that we respond to them by avoiding or maybe trying to neutralize them (I don't know if you do that but avoidance is a response in itself, as is trying to get rid of them). That response flags them up as something important and actually tells our brain to engage with them rather than let them pass. Then you dread the thought coming back, which means that due to that fear the thoughts remain in your consciousness and come back. It is partly the old classic of trying not to think of a pink elephant for the next two minutes. Do not let the words pink elephant enter your head, starting now...'argh, pink elephant, pink elephant....something else, yes I can do it....pink elephant.'.
So therapy might involve writing down your thoughts and deliberately setting aside a time every day to read them over and over. Spending 30 mins at a time deliberately focusing on the thoughts. It is a nightmarish prospect, particularly if you feel bad things will happen if you don't respond in some way to neutralise or escape them. Deliberately going to the places/doing the actions you have been avoiding. The theory (and it has worked for many apparently) is that this breaks the dynamic of seeing the thoughts as something we have to avoid, and gradually they will then stop entering your head as they are no longer seen as important. They will come sometimes but with less distress, apparently, and in fact everyone has intrusive thoughts to a small extent.
Depending on your symptoms and what other issues you do or don't have there might be other kinds of therapy or tactics that would help more, so I'm not saying the above is the only way. I just don't know about any others but perhaps someone else will. If you have PTSD the treatment might be different. I wouldn't wade into exposing yourself to the thoughts without getting some advice first, you may well need to do some preparatory stuff first. I wouldn't want you to traumatize yourself further, I'm just hinting at what they might do. Sorry if you already know all this.
I think there is a book about this called 'The Imp of the Mind' but I haven't read it.