You can’t really make the thoughts stop. But you can keep yourself from acting on them (not that it’s likely for you to do so, when they’re intrusive thoughts).
What worked for me, when I was having this problem, was forcing myself to think of something else and also disowning the thoughts - I wasn’t the one who wanted to think about these sorts of things, it was my brain throwing up garbage and that meant it should be given as much respect as a teenager trying to prove how edgy they are by yelling the worst things they can think of. (That is to say, none.)
So, when one of those thoughts comes up? “Shut up, Steve” (or whatever you’d like to call your pseudo-edgy imaginary teen) followed by dragging your train of thought back to what you were focusing on before. Don’t linger on the distress or the disgust and self-loathing - that grinds the intrusive thought in deeper, and makes it more likely that they’ll keep reoccurring.
Intrusive thoughts are scary, but by denying their existence, we make them stronger. Most people, yourself probably included, don't have very good control of their thoughts. Chances are that you didn't choose to have these thoughts. Therefore, it's not you, it's just your mind playing tricks in you. Like the statement “Don't think about a purple elephant!”
Alright, what did you think of?
Ive had these intrusive thoughts so I speak from experience. Next time it happens, accept that your mind made that thought and it’s not you. Look at the thought from an impersonal, outside point of view. It's much easier to let them go when you don't take them personally and as a reflection of who you are. Just observe and let them pass.
It’s easy to believe that the thoughts we have define who we are: “Well it entered into my brain. It is my brain. So, I must be responsible for the creation of the thought. It’s who I am”
This isn’t true. Our thoughts don’t always reflect who we are. Or our values. Our thoughts don’t have to define us. Clients I work with are often relieved to hear this. because it’s easy for us to identify with our thoughts.
We have zero control over the thoughts that enter our brains. And you are not responsible for the creation of the sick, bizarre, illegal, crazy junk that pops into your mind. You did not create it.
And all that junk that pops up, it’s completely normal. We all do it. We just don’t go around talking about it. If we did, we wouldn’t have any friends.
The problem is not the fact that your mind gives you negative thoughts; the problem is that you take your mind so seriously. Just because your mind says something is important does not mean it actually is important. Just because something feels important also does not mean it is important.
Thoughts are just thoughts.
Thoughts are not facts. Thoughts are not meaningful. The content of your thoughts is not important.
What is important is how you treat your mind. If you take everything it says seriously, give it too much respect, and put too much trust in your mind, that is a recipe for an anxiety disorder.
Remember, when you treat your mind this way, it doesn't mean your mind will necessarily stop saying things like this. Your mind is going to do what it wants to do; you don't have control over the thoughts that pop into your head. No one actually does. The important thing is not what thoughts you have, it's what you do when you have those thoughts.
Even though you can't stop your mind from continuing to give you negative thoughts, that's okay, because thoughts are just thoughts.