The plaintiff appeals from a final decree dismissing a bill of complaint. The final decree entered was based upon the defendant's motion for "Allowance of Final Decree" accompanied by an "Affidavit of Counsel." The defendant's motion and the affidavit of counsel alleged that a prior bill of complaint contained "almost identical . . . prayers for relief . . ." and that "[t]he facts . . . have all been alleged . . . either in a [b]ill of [c]omplaint or the contempt petition" between the same parties; it further alleged that both the prior bill of complaint and a contempt petition were "dismissed" upon the defendant's motions. The judge allowed the present motion after examining the papers in the prior suit and finding that the statements contained "in the supporting affidavit" were fact. The defendant argues, in substance, that its motion to dismiss should be treated as a plea in bar. We treat pleadings according to their nature and substance. See Commonwealth v. Wakelin, 230 Mass. 567 , 571; Essex Trust Co. v. Averill, 321 Mass. 68 , 70; Employers' Liab. Assur. Corp. Ltd. v. Traynor, 354 Mass. 763 . The defendant argues that its defence of res judicata raised by its motion should be sustained. We disagree. "Res judicata is an affirmative defence." Hacker v. Beck, 325 Mass. 594 , 598. The burden is on the party claiming res judicata by reason of a prior adjudication to allege enough facts in
his plea or motion to establish that the cause of action was (1) between the same parties; (2) concerned the same subject matter; and (3) was decided adversely to the party seeking to litigate the subject matter again. See New England Home for Deaf Mutes v. Leader Filling Stations Corp. 276 Mass. 153 , 157. A party relying on res judicata as an affirmative defence must prove either from the record of the former action or from extrinsic evidence the subject matter decided in the earlier judgment. Daggett v. Daggett, 143 Mass. 516 , 521. Cote v. New England Navigation Co. 213 Mass. 177 , 182. Boston & Maine R.R. v. T. Stuart & Son Co. 236 Mass. 98 , 102. Moreover, a dismissal based on mootness is not a decision on the merits. See Knowlton v. Swampscott, 280 Mass. 69 , 72-73. The record discloses no evidence which would warrant us in concluding that the first case was decided adversely to the plaintiff on the merits. Thus the defendant has not met its burden as to the affirmative defence of res judicata. The issues relating to the merits are not properly before us and we do not decide them. The final decree dismissing the bill of complaint is reversed and the case is remanded to the Superior Court.