
157 P.3d 16 (2007)
2007-NMSC-017
STATE of New Mexico, Plaintiff-Petitioner,
v.
Alex TRUJILLO, Defendant-Respondent.
No. 29,943.
Supreme Court of New Mexico.
April 3, 2007.
*17 Gary K. King, Attorney General, James W. Grayson, Assistant Attorney General, Santa Fe, NM, for Petitioner.
John Bigelow, Chief Public Defender, Kathleen T. Baldridge, Assistant Appellate Defender, Santa Fe, NM, for Respondent.

OPINION
CHÁVEZ, Chief Justice.
{1} Defendant Alex Trujillo was originally sentenced pursuant to a plea agreement that was silent on the issue of habitual-offender proceedings. After revoking Trujillo's supervised probation and adjudicating him as a habitual offender, the trial court enhanced Trujillo's underlying sentences. Concluding that Trujillo's plea agreement with the State was violated, the Court of Appeals vacated the enhancements in a memorandum opinion. State v. Trujillo, No. 25,583, slip op. at 7-8 (N.M. Ct.App. June 29, 2006). The State argues that Trujillo failed to preserve his argument that the plea agreement was ambiguous on the issue of whether his sentence could be enhanced if his probation was revoked. We agree. Thus, we reverse the Court of Appeals and affirm Trujillo's enhanced sentence.
I. BACKGROUND
{2} In August of 2002, Trujillo pled guilty to two counts of aggravated battery against a household member and one count of aggravated assault against a household member. In exchange for Trujillo pleading guilty, the State dismissed eight other charges and stipulated to a maximum sentence of seven and one-half years of incarceration (three years on each of the battery charges and eighteen months on the assault charge). Of that total, five years were to be suspended on condition that he be placed on supervised probation for five years. This arrangement, in which there was no mention of habitual-offender proceedings or prior convictions, was formalized in a plea and disposition agreement and later accepted by the trial court.
{3} In late 2003, Trujillo was released from prison and placed on supervised probation. In May of 2004, the State moved the trial court to revoke Trujillo's probation. In July of 2004, the State amended its motion and, at the same time, filed a supplemental information charging Trujillo as a habitual offender. Trujillo did not object to this filing. Three months later, the trial court held a hearing and revoked Trujillo's probation. At the end of the hearing, the trial court *18 stated that it would hear sentencing on the revocation at the same time that it would consider the State's motion for enhancement. Although at that time Trujillo objected to the form of the State's pleading, he did not object to the enhancement on the grounds that it violated his plea agreement.
{4} In the period between his probation being revoked and his resentencing, Trujillo filed a motion in which he argued that his counsel at the revocation hearing was ineffective for having called a certain witness. No objection was made in this motion to the State's filing of the supplemental information charging Trujillo as a habitual offender.
{5} In December of 2004, the trial court held a hearing to address sentencing on the revocation and the habitual-offender enhancement issue. The trial court concluded that Trujillo had one prior conviction and, pursuant to the habitual offender statute, enhanced each of Trujillo's three sentences by one year. At the hearing, Trujillo did not argue that he could not be sentenced as a habitual offender. In fact, Trujillo's counsel specifically stated: "He is going to have to do the mandatory time, because the court doesn't have the discretion on that one." Trujillo's counsel simply asked the trial court to run the assault charge concurrent with one of the battery charges, thus only giving him eight years of exposure. Due to the revocation of probation, the trial court also reinstated Trujillo's original sentences, but suspended one and one-half of those years. Trujillo is currently serving a nine-year sentence followed by one and one-half years of probation.
{6} For the first time, Trujillo contended on appeal that he could not be sentenced as a habitual offender due to the fact that his plea agreement was silent on this issue. The Court of Appeals agreed with Trujillo, holding in a memorandum opinion: "If the State wanted to subject Defendant to an enhanced sentence if he violated the terms of his probation, it was required to do so in the plea and disposition agreement." Trujillo, No. 25,583, slip op. at 8. The Court of Appeals affirmed the trial court's revocation of his probation, but vacated Trujillo's enhanced sentence. Id. at 5, 8. According to the court, Trujillo reasonably interpreted the plea agreement when he entered the plea to preclude an enhancement in the event he violated probation. Id. at 7.
II. DISCUSSION
{7} The State first argues that the Court of Appeals erred in considering Trujillo's claim because he did not preserve it. Trujillo responds that the enhanced sentence is illegal "under the circumstances of this case," and that a claim of an illegal sentence need not be preserved. Trujillo further argues that, because of its silence on the issue of habitual-offender enhancements, his plea agreement was ambiguous and that the ambiguity should be construed in his favor. Because we agree with the State's argument that the Court of Appeals erred in considering Trujillo's claim, we reverse the Court of Appeals and affirm the trial court's enhancement of Trujillo's sentence.
{8} For an issue to be preserved for appellate review, the general rule is that a party must fairly invoke a trial court's ruling. See Rule 12-216(A) NMRA; State v. Alingog, 117 N.M. 756, 760, 877 P.2d 562, 566 (1994). However, jurisdictional issues may be raised for the first time on appeal. Rule 12-216(B) NMRA. Because a trial court does not have subject-matter jurisdiction to impose a sentence that is illegal, the legality of a sentence need not be raised in the trial court. State v. Shay, 2004-NMCA-077, ¶ 6, 136 N.M. 8, 94 P.3d 8; State v. Perez, 2002-NMCA-040, ¶ 11, 132 N.M. 84, 44 P.3d 530. Moreover, a plea of guilty does not waive jurisdictional errors. See State v. Hodge, 118 N.M. 410, 414, 882 P.2d 1, 5 (1994).
{9} There is no dispute that Trujillo did not fairly invoke the trial court's ruling on the issue of whether his plea agreement precluded the State from pursuing habitual-offender proceedings. The question for us is whether the trial court had subject-matter jurisdiction to enhance Trujillo's sentence. See State v. Ramirez, 89 N.M. 635, 642, 556 P.2d 43, 50 (Ct.App.1976) (stating that a jurisdictional defect "goes to the very power of the court to entertain the action"), overruled on other grounds by Sells v. State, 98 N.M. *19 786, 788, 653 P.2d 162, 164 (1982). If the trial court was statutorily or constitutionally precluded from sentencing Trujillo as a habitual offender, then Trujillo's enhanced sentence is illegal and he was not required to preserve his argument.
{10} "A trial court's power to sentence is derived exclusively from statute." State v. Martinez, 1998-NMSC-023, ¶ 12, 126 N.M. 39, 966 P.2d 747. The trial court was statutorily authorized to sentence Trujillo as a habitual offender since a "prosecutor may seek [an habitual-offender] enhancement at any time following conviction, as long as the sentence enhancement is imposed before the defendant finishes serving the term of incarceration and any parole or probation that may follow that term." State v. Freed, 1996-NMCA-044, ¶ 8, 121 N.M. 569, 915 P.2d 325. If the State exercises its discretion and seeks such an enhancement during the appropriate time frame, the trial court is obligated to impose the enhancement once the defendant is proven to be a habitual offender. See NMSA 1978, § 31-18-20(C) (1983). In this case, Trujillo had not finished serving his probationary term when the State elected to seek enhancement of his underlying sentence. Thus, once the State proved Trujillo was in fact a habitual offender, the trial court was statutorily required to impose the enhancement.
{11} On the other hand, if, based on his plea agreement, Trujillo had an objectively reasonable expectation of finality in his original sentence, the constitutional proscription against twice being put in jeopardy would have divested the trial court of its authority to sentence Trujillo as a habitual offender. See March v. State, 109 N.M. 110, 111, 782 P.2d 82, 83 (1989) ("Sentencing may violate concepts of double jeopardy if not within objectively reasonable expectations of finality."). Therefore, in order for Trujillo's enhancement to be illegal such that the trial court was stripped of jurisdiction to impose it, two things must be present: (1) Trujillo must have had an expectation of finality in his original sentence; and (2) that expectation must have been reasonable. For the following reasons, we conclude Trujillo never had any expectation of finality in his original sentence, reasonable or not.
{12} Notwithstanding numerous opportunities to do so, Trujillo failed to object to being charged as a habitual offender. Specifically, Trujillo did not object: (1) when the State filed an amended motion to revoke his probation and, at the same time, filed a supplemental information charging him as a habitual offender; (2) when his probation was revoked and the trial court stated that it would consider the enhancement issue when it resentenced him on the revocation; (3) in his motion filed after the revocation, but before being resentenced; or (4) at his resentencing when he was sentenced as a habitual offender. Indeed, during the resentencing hearing, Trujillo's counsel specifically stated that the trial court was required by law to sentence him as a habitual offender. Moreover, Trujillo did not raise the issue in his docketing statement to the Court of Appeals. Had Trujillo had an expectation of finality in his original sentence in the first place, we would expect Trujillo to have raised the issue at some point before his briefing to the Court of Appeals. Moreover, the plea agreement's silence on the subject of habitual-offender charges cannot inure to Trujillo's benefit. The State may seek habitual-offender status at any time "before the defendant finishes serving the term of incarceration and any parole or probation that may follow that term." Freed, 1996-NMCA-044, ¶ 8, 121 N.M. 569, 915 P.2d 325.
{13} Since there is clear statutory authorization for his enhancement, the only way Trujillo could have avoided the preservation requirement is on constitutional grounds  namely double jeopardy. However, double jeopardy only protects Trujillo if, first, he had an expectation of finality in his original sentence and, second, that expectation was reasonable. Given his failure to object despite repeated opportunities to do so, the record does not support concluding that Trujillo had an expectation of finality in his original sentence. Thus, because the enhancement was statutorily authorized and because double jeopardy did not limit the trial court's jurisdiction to enhance Trujillo's sentence, the enhancement was not an illegal *20 sentence. We reverse the Court of Appeals on grounds of lack of preservation and affirm the trial court's sentencing of Trujillo as a habitual offender.
III. CONCLUSION
{14} Trujillo's habitual-offender enhancement was not an illegal sentence; thus, Trujillo is not excused from the requirements of preservation. Trujillo failed to preserve his argument that his plea agreement with the State precluded an habitual-offender enhancement. We reverse the Court of Appeals and affirm the trial court's enhancement of Trujillo's sentence.
{15} IT IS SO ORDERED.
WE CONCUR: PAMELA B. MINZNER, PATRICIO M. SERNA, PETRA JIMENEZ MAES and RICHARD C. BOSSON, Justices.
