
206 S.W.3d 680 (2006)
Ex parte Randolph Roy SPARKS, Applicant.
No. AP-75083.
Court of Criminal Appeals of Texas.
September 20, 2006.
Rehearing Denied November 15, 2006.
Karen K. Suggs, Dallas, for Appellant.
Kathleen A. Walsh, Assistant District Atty., Denton, Matthew Paul, State's Atty., Austin, for State.

OPINION
WOMACK, J., delivered the opinion for a unanimous Court.
The issue is whether post-conviction habeas corpus is available when a felony conviction was rendered on a guilty plea when in fact the offense was a misdemeanor. We hold that it is.
The State indicted Sparks for the offense of driving while intoxicated. Such *681 an offense is a Class B misdemeanor[1] unless it is shown that the offender has a previous conviction for a similar offense. A showing of one previous conviction enhances the offense to a Class A misdemeanor;[2] two previous convictions enhance the offense to a felony of the third degree.[3]
At the time of Sparks's offense on May 3, 2003, former Section 49.09(e) of the Penal Code limited the use of many prior convictions for enhancement purposes after ten years had elapsed. The relevant part of the statute read:
[A] conviction may not be used for purposes of enhancement under this section if:
(1) the conviction was a final conviction under Subsection (d);
(2) the offense for which the person is being tried was committed more than 10 years after the latest of:
(A) the date on which the judgment was entered for the previous conviction;
(B) the date on which the person was discharged from any period of community supervision on which the person was placed for the previous conviction;
(C) the date on which the person successfully completed any period of parole on which the person was released after serving a portion of the term to which the person was sentenced for the previous conviction; or
(D) the date on which the person completed serving any term for which the person was confined or imprisoned for the previous conviction; and
(3) the person has not been convicted of an offense under Section 49.04, 49.05, 49.06, 49.065, 49.07, or 49.08 or any offense related to operating a motor vehicle while intoxicated within 10 years of the latest date under Subdivision (2).[4]
The indictment of Sparks alleged that the 2003 offense was a felony because of prior convictions for DWI that were entered on August 17, 1979 and June 24, 1997. If Sparks had not been convicted of a relevant offense within 10 years after the punishment for the 1979 conviction was completed, Section 49.09(e) would have forbidden its use for enhancement of the 2003 offense to a felony.[5] Even if it were enhanced by the 1997 conviction, the 2003 offense could have been no more than a Class A misdemeanor,[6] for which the maximum punishment was one year in jail and a $4,000 fine.[7]
Sparks pleaded guilty as charged, judicially confessed, and agreed to the stipulation of evidence. The indictment also alleged that he had been convicted of the felony offense of aggravated assault, which enhanced the punishment for a felony DWI to that of a second-degree felony.[8] He received a sentence of eight years in prison. He did not appeal.
*682 Sparks now claims that habeas corpus lies because the district court did not have jurisdiction of a misdemeanor case. His claim is incorrect. The indictment in this case alleged misdemeanor DWI, enhanced to a felony by two prior DWI convictions. This pleading invoked the jurisdiction of the district court for the felony that was alleged, and that jurisdiction extended to the misdemeanor offenses that were included in the indictment.[9] The extension of the court's jurisdiction is provided by Article 4.06 of the Code of Criminal Procedure:
4.06. When felony includes misdemeanor
Upon the trial of a felony case, the [district] court shall hear and determine the case as to any grade of offense included in the indictment, whether the evidence shows a felony or a misdemeanor.
Although, on the facts of this case, former Section 49.09(e) made it improper to use the 1979 conviction, that was a matter of evidence. The evidence might have shown that the 1979 conviction could have been used because the conditions of Section 49.09(e) were met. If, for example, there was evidence that Sparks had been convicted of another DWI offense in 1988, the enhancement of the 2003 offense to a felony could have been accomplished. The very reason for the district court to have jurisdiction of misdemeanor offenses that are included in the felony offense is that the evidence might prove the misdemeanor without proving the felony. Because of Article 4.06, the district court had jurisdiction of the misdemeanor DWI offense of which the applicant admits being guilty.
But lack of jurisdiction is not the only ground of habeas-corpus relief for a person in Sparks's situation. We granted relief in the similar case of Ex parte Arnold.[10] It was a habeas-corpus attack on a conviction for a DWI offense that was enhanced to a felony by a prior DWI prosecution that, in fact, had not led to a final conviction. Like Sparks, Arnold claimed the district court lacked jurisdiction. We rejected the claim, and instead we held that the trial court was authorized to enter a sentence only for the lesser offense. Therefore, we determined that the proper relief was to set aside the felony conviction and to instruct the district court to enter a judgment of conviction for the misdemeanor offense and to assess punishment accordingly.[11]
The State argues that the present case is controlled by Smith v. State,[12] in which we held that a judgment of guilt for felony DWI could not be reversed on appeal for insufficient evidence when a prior conviction that was more than ten years old was used to enhance the offense. In that case the appellant stipulated to the prior convictions. He agreed to do that in his jury trial by, as his counsel put it, "admitting that they don't have to prove up these two things; and we don't get into the issue of [his] priors at this trial." Smith did so, as his counsel put it to him in a statement for the record with which he agreed, "rather than have the State prove up the DWI *683 convictions and running the risk of other things coming in that would be counterproductive to our position."[13] We held that, after stipulating the evidence and excusing the State from its burden of proof, Smith could not argue on appeal that the record was insufficient to show any evidence that would have made the older conviction useable for enhancement. We said, "In this case, the prior convictions element was not contested but was instead confessed to by stipulation. Under these circumstances, appellant has lost the ability to complain about the remoteness of the prior conviction."[14] We added in a footnote that "stipulating to the priors to avoid the introduction of damaging evidence arguably rises to the level of estoppel, when it comes to challenging the legitimacy of using those priors."[15]
The State argues that Sparks is in the same position because, when he pleaded guilty he judicially confessed, agreed to the stipulation of evidence, and waived defects in the indictment. To begin with, indictment defects are irrelevant, because neither Sparks's case nor Smith's had anything to do with the validity of the indictment. The question in both cases turns on evidence, and evidence is treated differently on appeal than it is in habeas corpus.
On appeal, the appellant may challenge whether the record contains evidence that was legally sufficient to meet the prosecution's burden to prove guilt beyond a reasonable doubt. Our holding in Smith was that a defendant may not agree at trial to excuse the State from introducing evidence to meet that burden, and then claim on appeal that the record does not show that the State introduced evidence to meet the burden.
On habeas corpus, the burden is on the applicant. When an applicant who has been convicted claims that he is actually innocent, and he proves it, he will be relieved from the restraint of the conviction even though he may have pleaded guilty and confessed.[16]
Smith, who stipulated to a fact to avoid the unfavorable effect of the jury's receiving evidence of the fact, may not complain on appeal that the State failed to present enough evidence to carry its burden of proof. But Smith could undertake to prove on habeas corpus that in fact he is innocent of the offense. Sparks may do the same, even though he pleaded guilty, confessed, and stipulated to evidence.
In this habeas proceeding, Sparks has proved, and the State does not dispute, the fact that his DWI offense was not a felony. He was not guilty of the felony elements of the offense, and the judgment of guilt will be set aside. He will be remanded to the custody of the Sheriff of Denton County for proceedings in the district court consistent with this opinion, which may include his admission to bail.
It is so ordered.
NOTES
[1]  See PENAL CODE § 49.04(b).
[2]  See id., § 49.09(a).
[3]  See id., § 49.09(b)(2).
[4]  Act of June 13, 2001, 77th Leg., R.S., ch. 648, § 2, 2001 Tex. Gen. Laws 1213, 1214, repealed by Act of June 18, 2005, 79th Leg., R.S., ch. 996, § 3, 2005 Tex. Gen. Laws 3363, 3364.
[5]  See Getts v. State, 155 S.W.3d 153 (Tex.Cr. App.2005). Section 49.09(e) was in effect until September 1, 2005, when it was repealed. See Act of June 18, 2005, supra note 4.
[6]  See PENAL CODE § 49.09(a).
[7]  See id., § 12.21.
[8]  See id., § 12.42(a)(3).
[9]  Evans v. State, 402 S.W.2d 756 (Tex.Cr.App. 1966); McKenzie v. State, 159 Tex.Crim. 345, 347, 263 S.W.2d 562, 563 (1953) ("where the misdemeanor offense of drunk driving is not only included within the allegations of the indictment but is a constituent element of the felony offense [of drunk driving] charged, without which the felony offense does not exist . . . [the] trial court was not without jurisdiction to render the judgment [of guilt of misdemeanor drunk driving]").
[10]  574 S.W.2d 141 (Tex.Cr.App.1978).
[11]  Id., at 142.
[12]  158 S.W.3d 463 (Tex.Cr.App.2005).
[13]  Id., at 464.
[14]  Ibid.
[15]  Id., at 464 n. 14 (citation omitted).
[16]  See Ex parte Tuley, 109 S.W.3d 388, 392-94 (Tex.Cr.App.2002).
