Several times over the course of my more than 40 years with my company. (Yeah, I'm a rarity these days, I've only ever worked full time for one employer.)
I would have left 5 years ago when the boss they hired for me decided he didn't like me for some reason, despite the fact that I had done my job, and done it well for many years under three different bosses. But I need my medical benefits, and didn't want to have to pay for them for a decade before being eligible for Medicare.
So I ended up switching departments completely. I really don't care for the new position, and my new boss is not an easy personality to work with/for, but at this point in my career I'm not switching companies, and I am grateful that I wasn't just let go.