Madonna and Guy Ritchie have resolved a months-long custody dispute in New York over where their teenage son should live. Here, the former couple pose as they arrive to attend the screening of Nathan Rissman's film "I Am Because We Are" at the 61st Cannes International Film Festival on May 21, 2008.

Pop star Madonna and her ex-husband, British filmmaker Guy Ritchie, have settled their monthslong custody battle and agreed that their 16-year-old son, Rocco, will live with his father in London.

“They have officially settled,” a spokesman for the New York State Unified Court System told Newsday on Wednesday. “Any other information is sealed, as are any matrimonial proceedings in New York State.”

TMZ.com, citing court documents, said Madonna, 58, and Ritchie, who turns 48 on Saturday, were scheduled for a hearing in Manhattan on Wednesday. Hours beforehand, they told the judge they had reached an agreement between themselves. No terms were disclosed.

Ritchie’s attorney, Peter E. Bronstein, told The Associated Press that Rocco — who left Madonna’s Rebel Heart tour in Europe in December, to stay with his father — would continue living in London with Guy, director of films including Robert Downey Jr.’s two Sherlock Holmes movies and last year’s “The Man from U.N.C.L.E.”

A Manhattan court had ruled in December that Rocco be returned to Madonna in New York. At a subsequent hearing in March, Guy Ritchie’s lawyer responded that, “Rocco is of an age where he cannot be physically forced to board a plane to come back.” Ellen Sigal, the teen’s attorney, said Rocco was enrolled at a London school under an agreement between the parents, and that, “Having this order over his head is stressful and upsetting to him.”

Madonna had also pursued legal action in the UK, under the 1980 Hague Convention on international child abduction. In March, a British judge implored her and Ritchie “to seek, and to find, an amicable resolution to the dispute between them,” and said it would be “a very great tragedy for Rocco if any more of the precious and fast-receding days of his childhood were to be taken up by this dispute.” The singer later withdrew her British case.

Madonna and Ritchie were married from December 2000 until their divorce was finalized in January 2009. Madonna additionally has a daughter, Lourdes, 19, with former companion Carlos Manuel Leon; an adopted daughter, Chifundo “Mercy” James, 8; and an adopted son, David Banda, who turns 11 later this month.

In July 2015, Ritchie married British model Jacqui Ainsley, with whom he has three young children.