After nine months of warring in and out of court, Madonna and Guy Ritchie have finally settled their custody dispute over their teenage son, Rocco.

A court spokesperson in New York said on Wednesday (September 7th) said that the duo had reached a settlement out of court, which was concluded just “hours before” they were both due to attend a court hearing regarding Rocco’s custody, TMZ reported.

The disagreement began back in December 2015 when Rocco, now 16 years old, quit his mother’s world tour after an argument about homework and mobile phones, and went to London to live with his filmmaker father. He then refused to return to Manhattan for Christmas with Madonna, leading to litigation being opened up before Christmas.

MadonnaMadonna in New York, May 2016

A judge quickly ruled that Rocco should return, but declined to issue a warrant to enforce that order. Rocco ignored it, and he has since remained with his father in the English capital, subsequently enrolling in school there.

The terms of the settlement are unknown, but it’s believed that Rocco will continue to be based in London, with regular visits from his mother.

More: Madonna’s son Rocco spotted in New York as custody stand-off with Guy Ritchie shows signs of easing

During a hearing in New York six months ago, Justice Deborah Kaplan said in no uncertain terms that the dispute was easily resolvable between Madonna (58) and Ritchie (47), and that they should settle it out of court.

“No one is disrupting his [Rocco’s] household other than the inability of the parents to reach a resolution,” Kaplan said after that hearing back in March. “If they cannot resolve this matter then eventually the court will.”

Ellen Sigal, a court-appointed representative for Rocco, also told the court at the time: “It’s been a very difficult time for him. We hope to put an end to this as soon as possible without exposing him to more litigation, press innuendo, any of that kind of thing.”

News reports in June, following an adjourned hearing, had indicated that the parents were nearing a deal. Ritchie and Madonna, who also have a 10 year old son, David, whom they adopted from Malawi, divorced in 2008 after eight years of marriage.

More: Has Rocco Ritchie just hit out at mum Madonna on Instagram?