I am a prosecutor.
Yes, trials occur when there are viable outcomes on all sides. But also:
1. One of the people involved in a criminal plea negotiations is irrational. (Prosecutor, defense attorney, defendant.) Defendants sometimes go to trial on crushing cases. Attorneys may want their clients to take a deal, and it doesn't happen.
2. There's no benefit to pleading for either side. If you've got a second degree murder with a fixed-by-statute sentence and the defendant is stone cold good for it, the prosecution may not offer a deal for the defense to take, and then the defense gets a trial because there's no harm to the client
In most jurisdictions, prosecutors win a very high percentage of trials because there are a lot of very good cases that go to trial.