The action was brought by the plaintiff to procure a judgment separating her from the bed and board of the defendant forever, and for a provision for the support and maintenance of herself and the two children of the parties, upon the ground of alleged cruel and inhuman treatment and failure to support. The answer denies the allegation of cruelty; admits that the plaintiff has had the custody of the children since September, : 1915; and alleges certain facts as a defense and in justification; and prays for judgment dismissing the complaint and that the court give such directions for the custody, care and education of the children as their interest may require. The learned trial justice after a trial of the issues granted judgment for the defendant dismissing the complaint, upon the merits, and further gave to the defendant custody of the children and established elaborate regulations for the conduct of the plaintiff., The question presented by this appeal is whether in an action for a separation, by the wife against the husband, the court,! having dismissed the complaint upon the ground that the \ facts proved did not establish the wife’s right to a decree of i separation, may, nevertheless, by its judgment in the action, / award to the defendant custody of the children of the marriage/ relieve the husband from the obligation to support the wife and restrain her from interfering with him. It would seem too clear for argument that affirmative relief could not be granted to the defendant unless he had sought such relief by counterclaim. Citation of authority for this proposition would seem unnecessary. The judgment in this action practically, although not in terms, grants the defendant a separation from the plaintiff. The respondent claims, however, that the court was authorized by sections 1766 and 1771 of the Code of Civil Procedure, in making provision for the custody and care of the children of the marriage, notwithstanding the fact that no judgment of separation was granted. While there would seem to be some justification for the claim, if we consider only the general language of those sections, yet when we take into consideration the limitations on the jurisdiction of the court in these actions and the construction that has been given to those sections and the provisions of *786the Revised Statutes (2 R. S. 147, § 55; 2 id. 148, .§ 59) from which they were derived, it is clear that it was not the legislative intent that such relief should be given on the facts presented by this case. • ■
In the case of Davis v. Davis (75 N. Y. 221) the court at Special Term had denied the relief sought in so far as it asked for a decree of separation, but did not dismiss the complaint but directed judgment awarding the custody of their children to the plaintiff and requiring the defendant to pay to the plaintiff a sum “for their support. In reversing the judgment the court said: “ The court was not authorized, in this action, after having denied judgment of separation, to award to the plaintiff the custody of the children, or make a decree for their support. The general jurisdiction which appertains to the Supreme Court, as a court of equity, to interfere for the "protection of infants * * * cannot be invoked to sustain the judgment in this case. In this statutory action the power of the court is to be sought in the statute itself, and only such judgment can be rendered as is authorized thereby.” And the court further points out that the remedy is by habeas corpus. (Pp. 227, 228.) That case was decided with respect to the provisions of the Revised Statutes. It was, however, applied to the sections of the" Code of Civil Procedure and it was held that an action could not be brought for maintenance and support without asking for a decree of separation. (Ramsden v. Ramsden, 91 N. Y. 281, 283.) This latter case applies to the defendant’s position in this case as he merely asks for the custody of the children of the marriage and not for a separation. The Appellate Divisions of the Second and Fourth Departments have applied the case of Davis v. Davis (supra) to the provisions of the Code of Civil Procedure (Robinson v. Robinson, 146 App. Div. 533; Kamman v. Kamman, No. 1, 167 id. 423), and have held that the provisions in section 1766 of the Code of Civil Procedure, that the court may in an action for separation render a judgment for the maintenance of the wife and children,, where, under the circumstances of the case, such a judgment is proper, without rendering a judgment of separation, apply onlyjwhere a separation can be decreed upon the evidence. The learned justice decided in the instant case that the evidence was insufficient to *787justify such a decree. The provision should not have been incorporated in the judgment.
Furthermore the parties had entered into a separation agreement On December 18, 1915, which provided that the plaintiff should have custody of the children and that the defendant v/as to pay her $150 monthly and an additional sum for the education of the children. This agreement has not been abrogated or set aside, and the court in this action had no power without granting a judicial separation to substitute an agreement of its drafting for that which the parties had voluntarily made themselves. Although there may not have been grounds for a judicial separation, the parties may agree to separate, under such terms as the law permits, and make such provision as they deem advisable for maintenance and support, and custody of the children. (Stoddard v. Stoddard, 187 App. Div. 258, 267; affd., 227 N. Y. 13.) The fact that this agreement provided that it might be abrogated or modified by any decree entered in an action for divorce brought by either party, conferred no jurisdiction on the court to abrogate or modify it. (Stoddard v. Stoddard, supra.) The court in a judgment granting a separation could as incidental relief make such provision for maintenance, support and custody of the children as it deemed wise, without regard for the terms of this agreement.
Inasmuch as the case was tried upon an erroneous theory of what was properly within the issues, and thus evidence that was prejudicial to the plaintiff was received, the interests of justice require that the findings and judgment be reversed and a new trial ordered, with costs to the appellant to abide the event.
Clarke, P. J., Dowling, Smith and Greenbaum, JJ., concur.
Judgment reversed and new trial ordered, with costs to appellant to abide event. Settle order on notice.