Many criminal cases are resolved out of court by having both sides come to an agreement. This process is known as negotiating a plea or plea bargaining. In most jurisdictions it resolves most of the criminal cases filed.
Plea bargaining is prevalent for practical reasons.
Defendants can avoid the time and cost of defending themselves at trial, the risk of harsher punishment, and the publicity a trial could involve. The prosecution saves the time and expense of a lengthy trial. Both sides are spared the uncertainty of going to trial. The court system is saved the burden of conducting a trial on every crime charged. Either side may begin negotiations over a proposed plea bargain, though obviously both sides have to agree before one comes to pass.