A plea agreement is a negotiated contract between a defendant’s attorney and the prosecutor that spells out the sentence that is acceptable to both parties. That sentence is then recommended to the court; it is then up to the court to accept or deny the terms of the plea agreement.
Provided the court accepts the terms agreed to, there will be no need for a trial. If the court does not accept the conditions, the defendant is generally allowed to withdraw the plea and choose to either plea without a plea agreement “straight up” to the court or go to trial.
Plea agreements have the advantage of certainty for the defendant. Almost always, the sentence agreed upon in the plea agreement is something less severe that the maximum allowable punishment under the law – otherwise there would be no reason to enter into a plea agreement.