
988 So.2d 950 (2007)
Ex parte Gary Lee BECK.
(In re Gary Lee Beck
v.
Attorney General Troy King et al.).
1060593.
Supreme Court of Alabama.
October 5, 2007.
*951 Gary Lee Beck, pro se.
Gregory O. Griffin, Sr., chief counsel, and Hugh Davis, deputy atty. gen., Alabama Board of Pardons and Paroles, for respondents.
LYONS, Justice.
Gary Lee Beck filed a complaint for a declaratory judgment in the Montgomery Circuit Court against Attorney General Troy King; Michael H. Feehan, a Calhoun County parole officer; Martha C. White, a hearing officer with the Alabama Board of Pardons and Paroles; Dewitt Ashley, an investigator with the Calhoun County Sheriff's Department; and Frederick Moore, the police chief of Ohatchee. The trial court entered a judgment dismissing Beck's complaint based on the doctrines of res judicata and collateral estoppel. Beck appealed the trial court's dismissal to the Court of Criminal Appeals. That court transferred the appeal to this Court; we transferred the appeal to the Court of Civil Appeals pursuant to § 12-2-7(6), Ala.Code 1975. The Court of Civil Appeals affirmed the trial court's judgment, without an opinion. Beck v. King (No. 2050940, November 17, 2006), 988 So.2d 956 (Ala.Civ.App. 2006) (table). Beck then petitioned this Court for a writ of certiorari, and we granted certiorari review. We affirm in part and reverse in part.

I. Facts and Procedural History

Beck was convicted of murder on February 29, 1988, and was sentenced to 20 years' imprisonment. He was paroled on March 30, 1998, and placed under Feehan's supervision. On November 6, 2000, Ashley arrested Beck for parole violations. Chief Moore was present at the time of the arrest. On November 20, Feehan issued a written report of parole violations, in which he charged Beck with three specific violations. On November 22, Feehan served Beck with a notice that there would be a hearing before a hearing officer with the Board of Pardons and Paroles, which took place on November 27. According to the portion of that notice on which Beck acknowledged its receipt, Beck did not request *952 an attorney to be present at the hearing, and he did not request that any witnesses be notified to be present for him. White, the hearing officer, concluded that Beck was guilty of the three parole violations and that evidence offered by Beck in mitigation did not outweigh the seriousness of the violations. White recommended that Beck's parole be revoked. On February 7, 2001, the Board of Pardons and Paroles concurred with White's recommendation and ordered that Beck's parole be revoked.
Beck petitioned the Montgomery Circuit Court for certiorari review of his parole revocation (case no. CV-01-2605). The circuit court upheld the revocation, and the Court of Criminal Appeals affirmed that judgment, without an opinion. Beck v. Alabama Bd. of Pardons & Paroles (No. CR-04-1432, February 24, 2006), 976 So.2d 520 (Ala.Crim.App.2006) (table). While that case was pending, Beck filed two cases in federal court. In 2002, he filed a habeas corpus petition in the United States District Court for the Northern District of Alabama, case no. CV-02-B-3013-W, naming as defendants Cheryl Price, whom he identified as a prison warden; the Alabama Board of Pardons and Paroles, and the Alabama attorney general. On April 22, 2004, the United States magistrate judge assigned to Beck's case filed a report and recommendation concluding that Beck's 2000 arrest was valid and denying his petition for a writ of habeas corpus. On May 21, 2004, the United States district judge to whom Beck's case was assigned adopted the magistrate judge's report, accepted his recommendation, and entered a judgment dismissing Beck's petition.
Beck also filed an action pursuant to 42 U.S.C. § 1983 in the United States District Court for the Middle District of Alabama, which the court transferred to the Northern District, case no. 7:02-CV-3050-LSC-HGD. Beck named as defendants in that case Feehan, Ashley, White, and Kairy Crum and Paul Whaley II, a classification specialist and the director of classification, respectively, with the Alabama Department of Corrections. On February 16, 2006, the United States district judge to whom the § 1983 case was assigned entered a summary judgment in favor of the defendants. Beck appealed that judgment to the United States Court of Appeals for the Eleventh Circuit, case no. 06-11621-E, but on July 10, 2006, the Eleventh Circuit dismissed the appeal as frivolous.
Beck filed the complaint in this case on May 5, 2005, in the Montgomery Circuit Court, seeking a judgment declaring that his arrest in 2000 was invalid because Feehan did not comply with § 15-22-31(b), Ala.Code 1975, which provides that a parolee may be arrested without a warrant only on "a written statement by said parole officer setting forth that the parolee has, in his judgment, violated the conditions of parole." Relying on Ex parte Dietz, 474 So.2d 127 (Ala.1985), in which this Court held that because § 15-22-54(d), Ala.Code 1975, requires a written statement from a probation officer for an arrest without a warrant on a charge of a probation violation, an arrest based only upon an oral statement from the probation officer was unlawful, Beck alleged that § 15-22-31(b) is not being applied in the same manner as is § 15-22-54(d), an analogous statute applicable to probationers.
Although not named by Beck as a defendant in the action, the Board of Pardons and Paroles moved to dismiss Beck's complaint. Thereafter, all five of the named defendants filed motions to dismiss. Attorney General King, Feehan, and White each raised the affirmative defenses of res judicata and collateral estoppel in their motions based on the federal court actions *953 and the prior Montgomery Circuit Court action; Ashley, the investigator with the Calhoun County Sheriff's Office, and Moore, the chief of police of Ohatchee, did not raise those affirmative defenses. Despite the fact that Ashley and Moore did not assert the doctrine of res judicata or collateral estoppel as an affirmative defense, the trial court dismissed Beck's complaint as to all the defendants on the basis that the complaint was barred by the doctrines of res judicata and collateral estoppel.
After the Court of Civil Appeals affirmed the trial court's judgment, Beck petitioned this Court for a writ of certiorari. Beck relied upon the ground found in Rule 39(a)(1)(D), Ala. R.App. P., i.e., that the decision of the Court of Civil Appeals was in conflict with prior decisions of this Court, the Supreme Court of the United States, the Court of Civil Appeals, or the Court of Criminal Appeals. He contends that because the issue of the legislature's intent in enacting § 15-22-31(b) was not addressed in his federal habeas proceeding,[1] the Court of Civil Appeals' affirmance of the trial court's judgment conflicted with authority setting forth the elements that a party asserting the affirmative defenses of res judicata and collateral estoppel must prove. He also contends that the Court of Civil Appeals' affirmance of the judgment conflicted with authority holding that a trial court may not sua sponte raise an affirmative defense on a defendant's behalf and then dismiss the action based on that defense. Finally, Beck relies upon the ground asserted in Rule 39(a)(1)(C), Ala. R.App. P., i.e., that his petition presents a question of first impression: Whether § 15-22-31(b) should be interpreted by this Court in accordance with this Court's interpretation of § 15-22-54(d), the statute concerning arrests for probation violations, which contains substantially the same language as § 15-22-31(b).

II. Standard of Review

"On certiorari review, this Court accords no presumption of correctness to the legal conclusions of the intermediate appellate court. Therefore, we must apply de novo the standard of review that was applicable in the Court of Civil Appeals." Ex parte Toyota Motor Corp., 684 So.2d 132, 135 (Ala.1996).

III. Analysis

In Lee L. Saad Construction Co. v. DPF Architects, P.C., 851 So.2d 507, 516-17 (Ala.2002), this Court discussed the elements of res judicata:
"Res judicata and collateral estoppel are two closely related, judicially created doctrines that preclude the relitigation of matters that have been previously *954 adjudicated or, in the case of res judicata, that could have been adjudicated in a prior action.
"`The doctrine of res judicata, while actually embodying two basic concepts, usually refers to what commentators label "claim preclusion," while collateral estoppel ... refers to "issue preclusion," which is a subset of the broader res judicata doctrine.'
"Little v. Pizza Wagon, Inc., 432 So.2d 1269, 1272 (Ala.1983) (Jones, J., concurring specially). See also McNeely v. Spry Funeral Home of Athens, Inc., 724 So.2d 534, 537 n. 1 (Ala.Civ.App.1998). In Hughes v. Martin, 533 So.2d 188 (Ala.1988), this Court explained the rationale behind the doctrine of res judicata:
"`Res judicata is a broad, judicially developed doctrine, which rests upon the ground that public policy, and the interest of the litigants alike, mandate that there be an end to litigation; that those who have contested an issue shall be bound by the ruling of the court; and that issues once tried shall be considered forever settled between those same parties and their privies.'
"533 So.2d at 190. The elements of res judicata are
"`(1) a prior judgment on the merits, (2) rendered by a court of competent jurisdiction, (3) with substantial identity of the parties, and (4) with the same cause of action presented in both actions.'
"Equity Res. Mgmt., Inc. v. Vinson, 723 So.2d 634, 636 (Ala.1998). `If those four elements are present, then any claim that was, or that could have been, adjudicated in the prior action is barred from further litigation.' 723 So.2d at 636. Res judicata, therefore, bars a party from asserting in a subsequent action a claim that it has already had an opportunity to litigate in a previous action."
Clearly, the four elements necessary to establish res judicata are present in this case. (1) There is not only one judgment, but several prior judgments, on the merits of Beck's claim that his parole was impermissibly revoked. (2) All of those prior judgments were rendered by courts of competent jurisdiction. (3) There is substantial identity of the parties named as defendants by Beck in the various actions. (4) The same cause of action, namely, a challenge to Beck's parole revocation, was presented in this and the previously filed actions. Beck's claim that Alabama's statute regarding arrests for parole violations, § 15-22-31(b), should be interpreted in line with this Court's interpretation of Alabama's similar statute regarding arrests for probation violations, § 15-22-54(d), could have been adjudicated in the prior actions. Certainly this claim could have been adjudicated in the first action Beck filed in the Montgomery Circuit Court (case no. CV-01-2605). The claim also could have been adjudicated in either of the actions Beck brought in the federal district court pursuant to the doctrine of supplemental or pendent jurisdiction outlined in United Mine Workers of America v. Gibbs, 383 U.S. 715, 86 S.Ct. 1130, 16 L.Ed.2d 218 (1966), and codified in 28 U.S.C. § 1367. In Parker v. Scrap Metal Processors, Inc., 468 F.3d 733, 742-43 (11th Cir.2006), the United States Court of Appeals for the Eleventh Circuit stated:
"Section 1367(a) authorizes a court to hear supplemental claims to the full extent allowed by the `case or controversy' standard of Article III of the Constitution. Palmer [v. Hospital Authority of Randolph County, 22 F.3d 1559,] 1566 [(11th Cir.1994)]. The constitutional `case or controversy' standard confers supplemental jurisdiction over all state *955 claims which arise out of a common nucleus of operative fact with a substantial federal claim. United Mine Workers of America v. Gibbs, 383 U.S. 715, 725, 86 S.Ct. 1130, 1138, 16 L.Ed.2d 218 (1966); Palmer, 22 F.3d at 1563-64 (a federal court has the power under section 1367(a) to exercise pendent jurisdiction over state claims which arise from the same occurrence and involve the same or similar evidence); L.A. Draper and Son v. Wheelabrator-Frye, Inc., 735 F.2d 414, 427 (11th Cir.1984) (a federal court may exercise pendent jurisdiction over state law claims deriving from a common nucleus of operative fact with a substantial federal claim)."
Because Beck has had numerous opportunities to litigate his claim, this action is properly barred by the doctrine of res judicata, and it is past time to end this litigation. Therefore, the Court of Civil Appeals properly affirmed that portion of the trial court's order dismissing Beck's complaint as to Attorney General King, Feehan, and White, who asserted in the trial court the affirmative defense of res judicata in their motions to dismiss.
We cannot apply the same reasoning to Ashley and Moore, however, neither of whom asserted in the trial court res judicata as an affirmative defense in his motion to dismiss. In Waite v. Waite, 959 So.2d 610, 612-13 (Ala.2006), this Court quoted from the Court of Civil Appeals' opinion in Waite v. Waite, 891 So.2d 341, 343-44 (Ala.Civ.App.2004), in which that court discussed the issue presented to us here:
"`The doctrines of res judicata and collateral estoppel are affirmative defenses, Rule 8(c), Ala. R. Civ. P.; Lee L. Saad Constr. Co. v. DPF Architects, P.C., 851 So.2d 507, 516 (Ala.2002), and do not affect a court's jurisdiction to consider an action. Affirmative defenses may be waived if they are not pleaded by a party against whom a claim is asserted. Rule 8(c), Ala. R. Civ. P.; Bechtel v. Crown Cent. Petroleum Corp., 451 So.2d 793 (Ala.1984) (citing 2A J. Moore, Federal Practice § 8.27[3] at 8-251 (2d ed.1948)). By its actions in the present case, the trial court, in essence, asserted the affirmative defenses of the doctrines of res judicata and collateral estoppel on behalf of the defendants and dismissed the matter based on those affirmative defenses.
"`After careful consideration, we find most persuasive the reasoning of the courts that have held that, although a trial court may dismiss an action on its own motion on a jurisdictional basis, affirmative defenses such as the statute of limitations or the doctrine of res judicata are not jurisdictional bases upon which a court may base a sua sponte dismissal. See Lease Partners Corp. v. R & J Pharmacies, Inc., [329 Ill.App.3d 69, 768 N.E.2d 54, 263 Ill.Dec. 294 (2002)]; Adams v. Inman, [892 S.W.2d 651 (Mo. Ct.App.1994)]. Therefore, we must conclude that the trial court erred in dismissing the action, on its own motion, based upon affirmative defenses not asserted by the defendants.'"
We adopt the Court of Civil Appeals' reasoning in Waite, and we hold that a trial court errs when it dismisses a case on the basis of an affirmative defense not asserted by the defendant. Therefore, we must reverse that portion of the Court of Civil Appeals' judgment affirming the trial court's order dismissing Beck's complaint as to Ashley and Moore, who failed to assert the affirmative defense of res judicata in their motions to dismiss.

IV. Conclusion

We affirm the judgment of the Court of Civil Appeals insofar as it affirmed the *956 trial court's order dismissing Beck's complaint as to Attorney General King, Feehan, and White. We reverse the judgment of the Court of Civil Appeals insofar as it affirmed the trial court's order dismissing Beck's complaint as to Ashley and Moore, and we remand the case to the Court of Civil Appeals for further proceedings consistent with this opinion.
AFFIRMED IN PART; REVERSED IN PART; AND REMANDED.
SEE, WOODALL, SMITH, BOLIN, and PARKER, JJ., concur.
STUART, J., concurs specially.
COBB, C.J., and MURDOCK, J., recuse themselves.
STUART, Justice (concurring specially).
The circuit judge to whom this case was originally assigned recognized that
"Gary Beck is unrestrained in his zeal for litigation, which involves the same issues over and over, as this complaint does, on issues that have been settled through judicial rulings and opinions. To continue with his unbridled litigious lust would be a gross abuse of the judicial system."
I agree; it is time to put an end to this litigation. However, I cannot ignore the Alabama Rules of Civil Procedure and caselaw.
"`[R]es judicata is an affirmative defense that must be especially pleaded in writing under [Ala. R. Civ. P.], Rule 8(c).' Wilger v. State Dep't of Pensions & Security, 390 So.2d 656, 657 (Ala.Civ. App.1980). `In some instances, res judicata may be properly raised by means of a motion to dismiss or, more commonly, through a motion for a summary judgment.' Wilger, 390 So.2d at 657."
Ryals v. Walden, 773 So.2d 1007, 1011 (Ala.Civ.App.1998). See also Hendricks v. Blake, 291 Ala. 575, 285 So.2d 82 (1973). The application of the Rules of Civil Procedure and Alabama caselaw requires that the circuit court's judgment be reversed as to defendants Ashley and Moore. Ashley failed to plead res judicata in the motion he styled as a "motion to dismiss, answer to plaintiff's complaint for declaratory judgment, and counterclaim." However, he can move to amend his answer, see Rule 15(a), Ala. R. Civ. P., specifically plead the affirmative defense of res judicata, and move for a summary judgment. Likewise, Moore, who did not plead the affirmative defense of res judicata in his motion to dismiss but who has not answered the complaint, can plead res judicata in his answer and move for a summary judgment.
NOTES
[1]  Beck's certiorari petition is misleading in that it refers to only one previous proceeding  the federal habeas corpus petition he filed in 2002. In fact, Beck has filed numerous legal actions, both state and federal, challenging different aspects of his 2000 arrest and the ensuing revocation of his parole. In addition to the two federal actions and the 2001 complaint filed in the Montgomery Circuit Court, Beck has been involved in the following litigation: Ex parte Beck (No. 1051535, July 31, 2006) (Ala.2006) (dismissing petition for writ of mandamus); Beck v. Alabama Board of Pardons & Paroles, 907 So.2d 1096 (Ala.Crim.App.2005) (appeal from Montgomery Circuit Court's dismissal of petition for writ of certiorari); Ex parte Beck, 923 So.2d 360 (Ala.Crim.App.2004) (table) (dismissing petition for writ of mandamus); Ex parte Beck, 920 So.2d 622 (Ala.Crim.App. 2004) (table) (dismissing petition for writ of mandamus); Beck v. State, 886 So.2d 185 (Ala.Crim.App.), cert. denied, 891 So.2d 1014 (Ala.2003) (table) (appeal from denial of Rule 32 petition); Ex parte Beck, 876 So.2d 1205 (Ala.Crim.App.2003) (table) (dismissing petition for writ of mandamus); and Ex parte Beck, 868 So.2d 492 (Ala.Crim.App.2002) (table) (granting petition for writ of mandamus).
