
12 So.3d 55 (2008)
Ex parte LCS INC.
(In re Carl Braxton Toole v. LCS Inc.)
1071668.
Supreme Court of Alabama.
December 19, 2008.
*56 Richard S. Manley and K. Scott Stapp of Manley, Traeger, Perry & Stapp, Demopolis, for petitioner.
Carl Braxton Toole, pro se.
LYONS, Justice.
LCS Inc. petitions this Court for a writ of mandamus directing the Montgomery Circuit Court to dismiss the claims against it in the underlying action on the basis of res judicata. We grant the petition and issue the writ.

I. Factual Background and Procedural History

Carl Braxton Toole is an inmate in the Alabama correctional system. During his incarceration he has been moved from prison to prison, including a private prison in Louisiana operated by LCS Inc. On October 3, 2006, while incarcerated in Louisiana, Toole filed a 42 U.S.C. § 1983 action in the Evangeline, Louisiana, District Court contending that he had been denied a fundamental right to access the law library in the private prison. Toole contended that the lack of access led to his being unable to file a brief in an appeal he had pending in the Alabama Court of Criminal Appeals from the denial of a Rule 32, Ala. R.Crim. P., petition for postconviction relief and that his failure to file the brief resulted in the dismissal of his appeal. The Louisiana district court entered a summary judgment against Toole on October 1, 2007.
On October 11, 2007, Toole, now back in an Alabama prison, filed a § 1983 action in the Montgomery Circuit Court asserting the same facts and law and seeking the same relief. LCS filed a motion to dismiss the Alabama action on the basis of res judicata and collateral estoppel; the trial court denied LCS's motion. LCS timely filed this petition on September 12, 2008.

II. Standard of Review

"`Mandamus is a drastic and extraordinary writ to be issued only where there is (1) a clear legal right in the petitioner to the order sought; (2) an imperative duty upon the respondent to perform, accompanied by a refusal to do so; (3) the lack of another adequate remedy; and (4) properly invoked jurisdiction of the court.'"
Ex parte Mardis, 628 So.2d 605, 606 (Ala. 1993) (quoting Ex parte Ben-Acadia, Ltd., 566 So.2d 486, 488 (Ala.1990)). Moreover, a petition for a writ of mandamus is an appropriate method by which to seek this Court's review of the denial of a motion to dismiss predicated on the doctrine of res judicata. Ex parte Sears, Roebuck & Co., 895 So.2d 265 (Ala.2004).

III. Analysis

Toole has filed two actions seeking the same relief in courts of proper jurisdiction in two states. The Louisiana complaint named as defendants LCS Inc. and three officers with the Louisiana corrections system. Toole alleged a § 1983 civil-rights *57 claim against the defendants "for denying plaintiff meaningful access to court and the denial [of] access to the law library at Pine Prairie Correctional Center which resulted in plaintiff losing his time to file an Appeal Brief" with the Alabama Court of Criminal Appeals. The Evangeline District Court adjudicated Toole's claim on its merits and entered a final judgment against Toole.
The Alabama complaint, as originally filed, named as defendants "in their individual capacity" Richard Allen, as commissioner of the Alabama Department of Corrections, and Patrick LeBlanc, as president of LCS Inc. Toole alleged that he was denied "his First Amendment Right to the United States Constitution to meaningful access to the courts, by depriving [him] access to the prison law library in a timely manner based upon a contract between the defendants and a policy written in one of the defendant's Inmate Offenders Handbook." Both defendants filed motions to dismiss. On April 30, 2008, the trial court granted Allen's motion to dismiss. On August 15, 2008, the trial court denied LeBlanc's motion to dismiss based upon the doctrines of res judicata and collateral estoppel. In the same order, the trial court granted Toole's motion for substitution of a party "such that Defendant, Patrick LeBlanc and/or his estate is hereby dismissed from this case and LCS, Inc. (Louisiana Correctional Services, Inc.) is hereby added as a named Defendant."[1]
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 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 *58 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 a prior judgment on the merits of Toole's claim that he was improperly denied access to the law library in the Louisiana prison operated by LCS; (2) the prior judgment was rendered by a court of competent jurisdiction; (3) there is complete identity of the partiesToole was the plaintiff in both actions, and, upon the trial court's order granting the motion for substitution, LCS, a defendant in the Louisiana action, became a defendant in the Alabama action; and (4) the same cause of action, namely, Toole's claim that he was denied access to the prison law library and thus to the courts, was presented in this and the previously filed action. The doctrine of res judicata applies not only to the exact legal theories presented in the prior action, but to "all legal theories and claims arising out of the same nucleus of operative facts." Old Republic Ins. Co. v. Lanier, 790 So.2d 922, 928 (Ala.2000). The doctrine of res judicata, therefore, bars Toole from asserting in the Alabama action the claim that he has already had an opportunity to litigate in the previous Louisiana action.

IV. Conclusion

LCS has shown a clear legal right to the relief it seeks in that it was entitled to have its motion to dismiss granted on the basis of res judicata. We therefore grant LCS's petition for the writ of mandamus and direct the Montgomery Circuit Court to enter an order dismissing Toole's claims against LCS.
PETITION GRANTED; WRIT ISSUED.
COBB, C.J., and STUART, BOLIN, and MURDOCK, JJ., concur.
NOTES
[1]  Neither party explains the substitution of LCS for LeBlanc. We interpret the trial court's order allowing LCS to be named as a defendant in place of LeBlanc "and/or his estate" to indicate that LeBlanc died during the pendency of this litigation.
