This is a very common and normal issue in almost every organization. It usually occurs when a subordinate is more competent than a senior. When you are more competent or a hard worker, your senior's job is at stake. This problem becomes more acute when a junior is acclaimed or praised by senior management.
I, too, have lost a good job in the same way. When I improved my qualifications, it set off alarm bells in the mind of my department head. The ego problem became more severe when a party, who had not released a payment after two visits from my boss, finally released the payment when I handled the issue.
As a result, harassment began, and I had to resign because harassment affects your behavior, resulting in disturbances in your work performance and false accusations. This type of harassment leaves no trail that can help you fight it. In cases of such agony, one is left with no choice but to resign. Otherwise, it is not difficult for management to fabricate false accusations.