The complaint alleges that on the first day of December, 1882, plaintiff, being about to leave Montana, gave to the defendant, Joseph Davis, a power of attorney, authorizing him to sell and convey the real estate of plaintiff in Lewis and Clarke County, said Territory. The plaintiff was then the *271owner of several described tracts of real estate in said county. The power of attorney was duly recorded February 2, 1885. On February 20,1885, the defendant, contriving to cheat plaintiff, and without consideration, conveyed said premises by two deeds to defendant, Bennett Price. Those deeds were executed, “Lewis Davis, by Joseph Davis, his attorney in fact.” They were acknowledged and recorded. That, in furtherance of defendant’s purpose to defraud plaintiff, said Price, on February 21, 1885, without consideration, conveyed said premises to Joseph Davis. The deeds are all pleaded in the complaint. That said transactions between Joseph Davis and Price were •fraudulent and void. Plaintiff prays that all said deeds be declared void, and that the title to the premises be adjudged to be in the plaintiff.
The answer contains some denials, which we need not consider in this decision. It then sets forth a separate defense, separately stated, which may be substantially stated, with the legal effect claimed, as follows: That the premises in controversy, or so much thereof as is necessary to notice in this consideration, were originally purchased by Lewis Davis, Joseph Davis, and another. That Joseph supplied the money to pay for his share in the same. That the deed was taken in the name of Lewis alone. That consequently, at the time of and prior to the acts complained of in the complaint, the legal title was in Lewis, but that there was a resulting trust created in favor of Joseph, and that Joseph had an equitable title in the premises when the power of attorney was made to him, and when he made the transfers complained of. It appears that Joseph, by the circumambulation through Bennett Price, as attorney in fact for Lewis, conveyed to himself, Joseph, the premises, in which, as appears by his answer, he claims he had the equitable title by virtue of the resulting trust suggested.
There was no replication. Plaintiff moved for judgment on the pleadings, “for the reason that the answer filed by the defendants does not present any sufficient defense to the cause of action set up in the plaintiff’s complaint.” The motion was granted, and judgment entered accordingly. From that judgment this appeal is taken.
We are to determine whether the new matter in the answer *272constituted a defense which could be presented in this action. The complaint is in equity. The new matter, if it be a defense, is an equitable one. For the purposes of this decision, we take the new matter as true, and, for convenience of treatment, will hereinafter speak of it as facts, and not merely allegations. Joseph Davis, by the power of attorney, was constituted the agent of Lewis Davis. He was in a fiduciary relation. Before the power of attorney was given, the legal title being in Lewis and the resulting trust existing, and the equitable title being in Joseph, Lewis was in a fiduciary capacity as to Joseph.
We will not cite authorities upon the general rule of equity, that an agent shall not unite his personal and representative capacities in the same transaction; that he shall not deal with himself; that an agent to sell for his principal shall not himself become the buyer, directly or indirectly; that an agent to buy for his principal shall not himself be the seller. These general doctrines are as old as the court of chancery. •
Respondent urges that the conveyances from Joseph, agent, to Joseph personally (for the mediation of Bennett Price is not material), must be set aside under the equitable rules cited. The lower court so held, and on that view gave judgment. The opinion on file bases the decision upon those doctrines.
We are of opinion, however, that there is another step in the case, another view of the situation of the parties as being in a court of equity, to which the attention of the District Court was not invited, and the opinion of that court does not treat of the subject which we will now discuss. Chapter 4, Code of Civil Procedure, provides: “Sec. 89. The answer of the defendant shall contain: .... Second, a statement of any new matter constituting a defense or counter-claim. .... Sec. 90. The counter-claim mentioned in the last section shall be one existing in favor of the defendant or plaintiff, and against a plaintiff or defendant, between whom a several judgment might be had in the action arising out of one of the following causes of action: First, a cause of action arising out of the transaction set forth in the complaint or answer as the foundation of the plaintiff’s claim or defendant’s defense, or connected with the subject of the'action. ; . . . Sec. 91. If the defendant omit to set up a counter-claim in the cases mentioned in the first subdivision of the last section, *273neither he nor his assignee can afterwards maintain an action against the plaintiff therefor.The defendant may set forth, by answer, as many defenses and counter-claims as he may have,” etc.
Was defendant’s new matter a defense or counter-claim, and, if so, under the provisions of the Code of Civil Procedure, supra, and by the rules of equity practice, may it be set up in the answer in the case? If so, judgment should not have been against the defendant on the pleadings, and the case should go back to the District Court for a determination of the equities. The subject suggests the following order of discussion:—
1. Is the new matter in the answer such that, if it were set forth in an original complaint in an action in equity, it would be entertained as entitling defendant to relief in such court That is to say, if a plaintiff' in a bill in equity allege that he furnished money to defendant to purchase land for him, that defendant purchased the land with the money, and took a deed to himself alone, either with or without plaintiff’s consent, do these facts entitle plaintiff to equitable relief? The authorities are uniform that they do. (Perry on Trusts, ch. 5; Story on Equity Jurisprudence, §§ 1201, 1206; Buck v. Swazey, 35 Me. 41; 56 Am. Dec. 681; Wood on Statute of Frauds, § 456; Edwards v. Edwards, 39 Pa. St. 369.) The defendant’s new matter is a good original cause of action in his favor against the plaintiff.
2. The defendant, Joseph Davis, having such original cause of action before the power of attorney was given to him by plaintiff, Lewis Davis, does the execution by Lewis Davis of such power of attorney deprive Joseph of his cause of action described? In other words, if such cause of action was put into a complaint by Joseph against Lewis, could Lewis defend by alleging the giving of the said power of attorney? It is reductio ad absurdum. The question answers itself in the negative.
3. Again, did the acceptance by Joseph of said power of attorney deprive him of such above-described cause of action ? Because he consented to act for Lewis as his agent in the caring for and disposition of the lands of Lewis, and also the lands of which the legal title was in Lewis and the equitable one in Joseph, does this consent, this acceptance of an agency, debar *274Joseph from demanding in a proper action and court rights which existed and were undisputed before the agency was created? Joseph Davis, having the cause of action set forth in paragraph 1, supra, could not be cut out of it by accepting the agency conferred by the power of attorney by any principle of law of which we are aware.
4. Again, after the power of attorney was given by Lewis and accepted by Joseph, did Joseph’s acts, under the power of attorney complained of in the complaint herein, deprive him of his cause of action above described? Counsel for respondent quote the equity maxims, “ He who seeks equity must do equity; ’.’ “He who comes into a court of equity must come with clean hands;” and argues that, because Joseph Davis took his own land and kept it, when it came into his own hands, by virtue of the creation of the agency by the power of attorney, he cannot be heard to assert his equitable right thereto at this time.
We must distinguish here between the state of facts in the case at bar and another one that might exist. Joseph obtained the power of attorney rightfully. It was the voluntary act of Lewis. The fiduoium was mutual. Lewis held Joseph’s title in trust for him. Joseph took Lewis’ power of attorney as a trust. On the other hand, if Joseph had obtained such power of attorney wrongfully — to illustrate it strongly, by actual violence, or duress per minas — and, after it were so obtained, by the authority thereof had conveyed the land to himself, and then had acquired an equitable title thereto, a court of equity would hesitate to hear him, and might then apply the maxim, “He who comes into a court of equity must come with clean hands.”
But the only proposition before us is, when Joseph was given by Lewis dominion over the land belonging to Lewis in law, and to Joseph in equity, and Joseph undertook, by the advantage of his agency to procure to himself the legal title, when he already held the equitable one, was that attempt of such a nature that the law visits the penalty of estopping Joseph from after-wards asserting that equitable title? The question is not now whether that attempt succeeded from a legal point of view, or whether Joseph obtained the legal title by his maneuvers, but whether he lias so conducted himself that he has lost his equity. The result could only occur through the operation of the rules *275of estoppel. Those rules are too familiar to require recitation. It is clear that their application to the facts under discussion cannot work an estoppel against Joseph Davis. (See Perry on Trusts, § 416.)
5. We therefore arrive at the conclusion that, prior to the time when the obnoxious deeds were made, an affirmative cause of action existed in favor of Joseph and against Lewis as above fully described, and that when the action was commenced Joseph had not lost the right to set. up that cause of action, and that the facts constituting the same are pleaded as new matter in the answer.
6. Such new matter would constitute a defense or counterclaim. (Code Civ. Proc. §§ 89, 90.) Defendant alleges it in the form of a defense. The prayer of the answer is that defendant be discharged. But the prayer in an equity action does not conclude the pleader. (Gillett v. Clark, 6 Mont. 191; Leopold v. Silverman, 7 Mont. 266.) The court may grant such relief as the party shows himself entitled to. The allegations in the new matter are sufficient for a counter-claim, on which the court could enter a decree adjudging the title to be in Joseph Davis, if it were deemed that the dismissal of the action, as prayed for in the answer, were not a sufficient confirmation of defendant’s title.
7. Such new matter is “connected with the subject of the action.” It is inseparably connected with the question of the title to the premises. The title to the premises is the subject of the action.
8. Defendant may set up such new matter in his answer. (Code Civ. Proc. §§ 89, 90.)
9. Quaere, must he not set it up, or be afterwards barred from asserting it? (Code Civ. Proc. § 91.)
10. Under the rules of practice in a court of equity, the court will hear an equitable defense or counter-claim, connected with the subject-matter of the petition, without regard to the provisions of the Code of Civil Procedure above cited. (1 Pomeroy’s Equity Jurisprudence, § 84, et seq.; Crary v. Goodman, 12 N. Y. 266; Dobson v. Pearce, 12 N. Y. 156; Bruck v. Tucker, 42 Cal. 346.)
11. It is a settled rule of equity practice that when the court *276bas before it all the parties to any difference, and when it has obtained complete jurisdiction of the whole subject-matter, it will finally settle the whole controversy. “The court may, on a view of the whole case, annex equitable conditions to its decree, or order what may be reasonable.” (Polk’s Lessee v. Wendal, 9 Cranch, 87.) The court, in the case before us, has, with the new matter in the answer, the ample purview contemplated by the rules of equity. It has the whole controversy and all the parties before it. Final adjudication of all the claims of Lewis Davis and Joseph Davis in the premises may be and should be made in one decree, ut sit finis litium. The judgment of the District Court, so far as it affects the validity of the deeds from Joseph Davis, as attorney in fact to Bennett Price, and the deeds from Bennett Price to Joseph Davis, is affirmed; but the cause is remanded, with directions to the District Court to entertain the equitable claim of defendant set up in his answer, and to hear and determine the claims of the parties in and to the premises in controversy.
Harwood, J., concurs. Blake, C. J., did not sit in the case, having been trial judge in the court below.