(A) Withdrawal Before Acceptance. The defendant has a right to withdraw any plea until the court accepts it on the record.
(B) Withdrawal After Acceptance but Before Sentence. Except as provided in subsection (3), after acceptance but before sentence,
(1) a plea may be withdrawn on the defendant's motion or with the defendant’s consent, only in the interest of justice, and may not be withdrawn if withdrawal of the plea would substantially prejudice the prosecutor because of reliance on the plea. If the defendant's motion is based on an error in the plea proceeding, the court must permit the defendant to withdraw the plea if it would be required by subrule (C).
(2) the defendant is entitled to withdraw the plea if
(a) the plea involves an agreement for a sentence for a specified term or within a specified range, and the court states that it is unable to follow the agreement; the trial court shall then state the sentence it intends to impose, and provide the defendant the opportunity to affirm or withdraw the plea; or
(b) the plea involves a statement by the court that it will sentence to a specified term or within a specified range, and the court states that it is unable to sentence as stated; the trial court shall provide the defendant the opportunity to affirm or withdraw the plea, but shall not state the sentence it intends to impose.
(3) Except as allowed by the trial court for good cause, a defendant is not entitled to withdraw a plea under subsection (2)(a) or (2)(b) if the defendant commits misconduct after the plea is accepted but before sentencing. For purposes of this rule, misconduct is defined to include, but is not limited to: absconding or failing to appear for sentencing, violating terms of conditions on bond or the terms of any sentencing or plea agreement, or otherwise failing to comply with an order of the court pending sentencing.
(C) Motion to Withdraw Plea After Sentence. The defendant may file a motion to withdraw the plea within 6 months after sentence. Thereafter, the defendant may seek relief only in accordance with the procedure set forth in subchapter 6.500. If the trial court determines that there was an error in the plea proceeding that would entitle the defendant to have the plea set aside, the court must give the advice or make the inquiries necessary to rectify the error and then give the defendant the opportunity to elect to allow the plea and sentence to stand or to withdraw the plea. If the defendant elects to allow the plea and sentence to stand, the additional advice given and inquiries made become part of the plea proceeding for the purposes of further proceedings, including appeals.
(D) Preservation of Issues. A defendant convicted on the basis of a plea may not raise on appeal any claim of noncompliance with the requirements of the rules in this subchapter, or any other claim that the plea was not an understanding, voluntary, or accurate one, unless the defendant has moved to withdraw the plea in the trial court, raising as a basis for withdrawal the claim sought to be raised on appeal.
(E) Vacation of Plea on Prosecutor’s Motion. On the prosecutor’s motion, the court may vacate a plea if the defendant has failed to comply with the terms of a plea agreement.