delivered the opinion of the Court.
This action was brought on August 18, 1949. Plaintiff alleged that he is the owner — by title acquired by purchase and recorded in the Registry of Property — and holds possession of certain property which is described in the petition, on which the American Railroad Company of Porto Rico and the Compañía Ferroviaria de Circunvalación de Puerto Rico 1 installed and maintained, against his express will and without any title or right thereto, a railway track, crossing *796the property from east to west, for the use of its trains, thereby depriving him of the convenient use and enjoyment of his property. Plaintiff moved that judgment be rendered at the proper time and after compliance with the legal requirements, ordering the defendants to remove and eliminate the tracks in question.
Defendants filed separate answers urging dismissal of the petition on the ground that it did not state facts sufficient to constitute a cause of action, denying generally and specifically the facts therein alleged, and alleging as special defenses that the Compañía de los Ferrocarriles de Puerto Rico was since 1891 the owner in fee simple of the parcel where the railway was installed for the use of the trains operated by the American Railroad Company of Porto Rico — a public-service corporation created and organized under the laws of the State of New York, and authorized to do business in Puerto Rico — whose capital stock was wholly controlled by the Compañía Ferroviaria de Circunvalación. Further, it stated that the railroad franchise was registered in its name in the Registry of Property of San Juan. As part of the' special defenses, it was alleged that the Compañía de Ferro-carriles de Puerto Rico had been for over thirty years in continuous possession, as owner, of the land where the railroad line was maintained, wherefore it had acquired dominion title by extraordinary prescription, that the action had prescribed under the provisions of § 1863 of the Civil Code, since more than thirty years- had elapsed since the action could have been exercised, as well as under the provisions of § 1868, subd. 1, of the Civil Code, since more than one year had elapsed from the time it could have been exercised until the filing of the petition. Each one of the three co-defendants prayed in its answer for dismissal of the petition in its entirety, with costs and attorney’s fees on plaintiff.
*797The issue thus joined, and after plaintiff requested the defendants to admit the facts and file their corresponding answers, as well as mutual interrogatories between plaintiff and codefendant the Compañía de los Ferrocarriles de Puerto Rico, which were timely answered, a trial was held commencing on May 10, 1951, before Rodolfo Ramírez Pabón, then Judge of the former District Court of Puerto Rico, San Juan Section and ending, after several continuances, on May 8, 1953.
On April 2, 1953 the Transportation Authority, as as-signee of all title or interest in the personal and real properties of the defendants, requested to be substituted in the proceeding as a party defendant, on the ground that it was the only party really interested in the suit. Thenceforth the Transportation Authority continued as defendant, having been required by plaintiff to produce certain documentary evidence in support of defendants’ title alleged to have been acquired by condemnation “to which the evidence for the defense herein is confined”, in order to be able to proceed with the trial on May 8, 1953. The trial having, ended on this date, the court granted thirty successive days ■ to the parties to submit briefs.
The same day the trial ended plaintiff moved in writing “for dismissal of this action as being academic, with costs and attorney’s fees on defendants,” alleging that since the action had been brought for the purpose of compelling defendants to remove the railway tracks which existed on petitioner’s property, “more than one year had elapsed since the railway was demolished and removed by the defendant party”, it being in his judgment “unnecessary to proceed with the case after the original cause of action had disappeared by the will of thé defendants.” In the meantime, on June 10, plaintiff filed his memorandum on the merits analyzing his evidence touching on the title over the parcel of land on which the railway was constructed, analyzing *798briefly the evidence of the defendant party — which, in his opinion, did not establish their claim of the alleged title by condemnation — and arguing against the alleged acquisitive prescription maintaining, on the other hand, that “when the railway in question was voluntarily demolished and removed while this action was pending, the defendants actually consented to the prayer of the complaint, which for that reason has rendered the action academic.”
On June 24 the defendant filed its brief, also analyzing the questions of fact and of law involved in the case. Defendant further questioned the propriety of the motion to dismiss filed by plaintiff on May 8, 1953, insisting that “it having been alleged in defendant’s (sic), answers that it was the owner in fee simple, by prescription, of the tracks and strip of land where such tracks were laid out, and it appearing that defendants have been in quiet, public, and peaceful possession as owners of the property and railway,” the lower court should decide the case on the merits “to the effect that defendant was the owner in fee simple by prescription of the railway tracks and strip of land where they are laid out.” 2
While the case was still pending before the judge who presided at the trial and to whom plaintiff’s motion of May 8, 1953 was submitted, the plaintiff moved on July 2 of that year for an order of “voluntary withdrawal from the suit,” to -which the defendant Transportation Authority objected by motion filed on the 8th of that month. The motion of dismissal was granted after a hearing held on July 18 before a Judge of the Superior Court other than the one who presided *799at the trial on its merits. His judgment granting the motion in question was as follows:
“The hearing of plaintiff’s motion praying for an order of dismissal was held on the 16th instant, with the sole appearance of plaintiff. The defendant party appeared by brief.
“This Court, in view of Rule 41(a) (2) of the Rules of Civil Procedure, and considering that the railway sought to be removed by this action was voluntarily demolished and removed by the defendant party; and considering that the trial of the case on its merits is no bar to the dismissal sought, since no judgment has as yet been rendered granting or refusing the relief sought in the petition; and considering that there is no petition for any affirmative relief against plaintiff, plaintiff’s motion is granted and the action dismissed by voluntary withdrawal, with costs on plaintiff.”
A motion for reconsideration was filed by defendant assailing the impropriety of the order of dismissal on the ground that the same question had been posed and was pending before Judge Rodolfo Ramírez Rabón, and alleging further, that the action had become one of revendication by reason of the evidence heard on defendant’s, dominion title to the parcel and tracks. The latter motion was denied on the 21st of the following August.
We issued a writ of certiorari to review the action of the lower court holding that the plaintiff had abandoned his action. In its memorandum in support of the issuance of the writ — submitted as brief on the merits of the petition— the Transportation Authority, petitioner herein, maintains that the lower court erred and abused its discretion in allowing plaintiff to abandon his action, (1) because dismissal does not lie over the objection of the defendant where the latter raises in his answer, or the evidence in the case establishes, that he is entitled to affirmative relief; (2) dismissal does not lie where the bulk of the evidence of both parties has been heard, and the court is in a position to determine definitively the rights of the parties; and (3) because the *800dismissal following the filing of an answer is a question which rests within the sound discretion of the trier, and the judge who ordered the dismissal in the instant case lacked elements of judgment enabling him to wisely exercise such discretion, since he did not hear or examine the evidence offered at the trial and ignored the controversy raised by that evidence, especially since an identical motion for dismissal was submitted to the consideration of the judge who heard the case on the merits.
Rule 41(a) (2) of the Rules of Civil Procedure provides that “an action shall not be dismissed at the plaintiff’s instance save upon order of the court3 and upon such terms and conditions as the court deems proper.” It also provides that “If a counterclaim has been pleaded by a defendant prior to the service upon him of the plaintiff’s motion to dismiss, the action shall not be dismissed against the defendant’s objection unless the counterclaim can remain pending for independent adjudication by the court. Unless otherwise specified in the order, a dismissal under this paragraph is without prejudice.” (Italics ours.)
Upon examination of the answers of the different defendants, in the light of the averments of the petition, it will be found that under the title of Special Defenses the former alleged, among other particulars, that the Compañía de los Ferrocarriles de Puerto Rico was the owner in fee simple of the parcel on which the railway which plaintiff sought to remove was installed, (1) on the ground thát it had been acquired in 1891 by condemnation, and (2) by acquisitive prescription.
The foregoing pleading partakes of the character of a counterclaim — Rule 13(a), (6) and (c) — rather than of an *801affirmative defense of those allowed under Rule 8(c),4 for the claim to the title to the parcel on which the railway was installed was made a part of the controversy and not merely alleged as a defense against the trespass alleged by plaintiff, wherefore defendants, by asserting the right to title by condemnation and prescription, transcended the limits of the action brought by plaintiff. Since then the action has become an action to quiet the dominion title to the parcel. In fact, the action was prosecuted as such by the parties through all its stages up to the motion for voluntary dismissal. The fact that that pleading was incorrectly designated by the party defendant as defense and not counterclaim, did not preclude the court under the latter Rule, from regarding it as if it had been correctly labelled, Thierfeld v. Postman’s Fifth Avenue Corporation, 37 F. Supp. 958, nor from rendering judgment under Rule 54(c), granting the relief to which it is entitled under the facts pleaded and the law, if any, irrespective of what is asked for in the prayer.5 Schoonover v. Schoonover, (C. A. Okla. 1949), 172 F. 2d 526; Hawkins v. Frick-Reid Supply Corp., (C. A. Tex. 1946), 154 F. 2d 88; Kansas City, St. L. & C. R. Co. v. Alton R. Co., (A.A. Ill. 1941), 124 F. 2d 780; Downey v. *802Palmer (C.A. N.Y. 1940), 114 F. 2d 116; Catanzaritti v. Bianco, 25 F. Supp. 457. Cf. Blake v. Clyde Porcelain Steel Corp., 9 F.R.D. 455.
Since the defendant Transportation Authority, objected to the dismissal of the action, such dismissal did not lie, as a question of law — not as a question of discretion of the court, Zegarra v. District Court, 66 P.R.R. 143— according to Rule 41(c) (2), unless the counterclaim could remain pending for independent adjudication by the court. In view of the attendant circumstances of the instant case, the bare fact of the removal of the railway by the defendant —for reasons of its own which do not imply the waiver of its alleged property right to the parcel where it was installed —should be no bar to the rendition of judgment on the merits of the claim, particularly in view of the fact that the litigation actually hinged throughout all its stages until the end of the trial — with the active participation of plaintiff — on that claim.
The judgment considering plaintiff as having voluntarily abandoned his action will be reversed and the case remanded to the original court for further proceedings not inconsistent with this opinion.
Mr. Justice Marrero and Mr. Justice Ortiz did not participate herein.Subsequently, on March 1, 1950, at the request of the Compañía Ferroviaria de Circunvalación, the lower court ordered the Compañía de los Ferrocarriles de Puerto Rico to appear in the action. This action by the court cured the alleged defect of the defendant party which both the American Railroad Company of Porto Rico and the Compañía Ferro-viaria de Circunvalación had raised in their answer.
On June 30, 1953, the Transportation Authority submitted a supplementary memorandum on the motion to dismiss filed by plaintiff praying the lower court “to dismiss plaintiff’s motion of dismissal based on the ground that the case is academic, and on the contrary to render judgment granting such relief as may be adequate on the pleadings and the evidence.”
Under Rule 41(a)(1) of the Rules, an action may be dismissed without order of the court “ (I) by filing a notice of dismissal at any time before service of the answer, or (II) by filing a stipulation of dismissal signed by all the parties who have appeared generally in the action.”
Rule 8 (c) : “Affirmative Defenses. — In pleading to a preceding pleading, a party shall set forth affirmatively any of the following defenses: Accord and satisfaction, arbitration and award, assumption of risk, contributory negligence, discharge in bankruptcy, duress, estoppel, failure of consideration, fraud, illegality, injury by fellow servant, laches, license, payment, release, res judicata, prescription, waiver, and any other affirmative defense. Any circumstance tending to reduce the amount of damages shall be affirmatively pleaded. When a party has mistakenly designated a defense as a counterclaim or a counterclaim as a defense, the court upon such terms as it may deem just, shall treat the pleading as if there had been a proper designation.”
Rule 54(c): “Demand for judgment. — A judgment by default shall not be different in kind from or exceed in amount that prayed for in the demand for judgment. Except as to a party against whom a judgment is entered by default, every final judgment shall grant the relief to which the party in whose favor it is rendered is entitled, even if the party has not demanded such relief in his pleadings.” (Italics ours.)