I have unwanted obsessive thoughts, too. Some origin from my social anxiety, some of my OCD, and some come from nowhere. I fight with them all the time, and it makes things only worse than they are. I have been reading a lot about it. I came to the conclusion, that the best way to deal with such thoughts is to let them be. Imagine you are in a closed room(no doors, no windows). In that room, it's only you, and a very aggressive cat. You can not escape from the room, and you can not take the cat out either. Hitting the cat towards the wall is making it only angrier. Instead of making the cat mad, just let it be. Accept that this is the way it is, that you can not change it. Just sit there and watch the cat, just watch it, don't react to what it is doing. The cat will still try to scratch you, maybe bite you, but keep calm. After a while the cat will get bored and fall asleep. Of course, when it wakes up, it will still try to make you mad, but keeping it calm and letting it just scratch you is far more effective than fighting it. And if you didn't get my cheesy story, in short: Accept your thoughts, and instead of trying to get rid of them, practice the skill of ignoring them. Learn that they are here, if you leave them alone, they will leave you alone.
Here are some wonderful guides to help you control obsessive thoughts:
Self-help guide:
https://www.anxietybc.com/sites/default/files/Managing_Obsessions.pdf (pdf version)
Information and self-help strategies:
https://www.calmclinic.com/anxiety/signs/obsessive-thoughts
Come back here to tell us how it was, does it help etc. You can also always contact some listener here, sometimes just sharing your obsessive thoughts helps. If those tips don't work on you, that's definitely a sign that you need some help from a mental health professional, such as getting medications or going to some therapy.
Wish you big luck!
I learned that the more you try to push or direct your obsessive thoughts away, the harder it is to get rid of them in the end. You can try to detach yourself from the thought, meaning just acknowledge it is there and nothing else. The specific thought has nothing to do with who you are as a person, despite what meaning we want to give to it.
It may seem hard to do this at first, but the more practice you do, the more you learn that the thought has no control over you, the easier it will be for the unwanted thoughts to stop surfacing.
Hope that helps!