For example, A caused the death of B. The crown lays a charge of first-degree murder against A.
But the crown, represented by the prosecutor, is not sure that it can win the case.
Likewise, the defendant and his/her lawyer are also not sure they can win, that is get an acquittal.
So they agree that the defendant will plead guilty to a lesser charge, such as second-degree murder.
(not a judge, lawyer, or criminal)