Church politics is one of the ugliest parts of the Christian life, but you have to learn how to deal with it. When David was unfairly demoted, he behaved himself wisely, and he continued to be a blessing to Saul. When he finally had to leave, he allowed Jonathan to bring about reconciliations between himself and Saul.
But David eventually made a final decision: he left Saul for good. In doing so, David deserted an army that needed him. He lost his chance to be a good influence on Saul. For years, he was separated from his wife. And when David's best friend needed him the most, David wasn't there.
Did David do the right thing in leaving Saul? He continued to serve God in exile, but on a smaller scale than he had before. Eventually, though, God raised up David to be king for forty years, defeating David's enemies on every side.
Many of those who stayed loyal to Saul were destroyed, but David, who separated from Saul, was successful. As painful as it is, when leadership turns corrupt, you need to leave.