If, in an action brought against such purchaser or other person claiming under the purchaser to recover possession of lands sold for taxes, the defendant claims and defends under the tax title and the defense fails on the ground that such sale was invalid for any reason other than that the taxes were not due, and the plaintiff recovers, the court shall forthwith, on the motion of the defendant, ascertain the amount of taxes for which the lands were liable at the time of the sale and for the payment of which they were sold, with interest thereon from the day of sale, and the amount of such taxes on the lands, if any, as the defendant or the person under whom he or she claims has, since such sale, lawfully paid or assumed, in case of the state, with interest thereon from the date of such payment, the interest on both amounts to be computed at the rate of 12 percent per annum, subject to the limitations set forth in Section 40-10-122(a); and the court shall thereupon render judgment against the plaintiff in favor of the defendant for the amount ascertained and the cost of the action, which judgment shall constitute a lien on the land sued for, the payment of which may be enforced as in other cases, and no writ of possession shall issue until such judgment has been satisfied, and the court may order the land sold or condemn it to the satisfaction of the debt.
Ala. Code § 40-10-77 (1975)