Madonna's long-documented custody battle for her son, Rocco, could have derailed her bid to adopt twin girls from Malawi.

A report on TMZ says the pop star settled her bitter custody battle with her ex-husband Guy Richie last September, and one of the main reasons was so that she could get the girls. If the fight had continued, the courts likely would have ended her bid to adopt.

"The judge who green lit Madonna's adoption last week spent a long time understanding the circumstances surrounding her custody dispute," TMZ reports, adding the dispute was of "paramount concern" because the judge didn't want the adopted kids thrown into a "toxic" family environment.

Madge and Guy settled the case on what appeared to be good terms, so the judge signed off on the adoption.

The battle for 16-year-old Rocco was intense. Madonna and Guy both slung insults and unflattering accusations at each other in determining where their son would live. In December 2015, Rocco was on tour with his mom, but bailed and went to London to live with his dad. Madonna claimed Guy has poisoned her son against her, but the two worked out a deal in which Rocco would continue school in London, but spend summers in New York City.

Madonna first applied to adopt Esther and Stella on January 25. On Feb. 7, the court signed off on the adoption and Madonna got custody of the twin girls. The reason why the process was so fast, the website says, is because Madge had already gone through the process twice in Malawi.

After Madonna first applied for the adoption, she denied it. Then, on Feb. 7, she confirmed the rumors on Instagram.

"I can officially confirm I have completed the process of adopting twin sisters from Malawi and am overjoyed that they are now part of our family," she wrote, alongside a pic of her and girls. "I am deeply grateful to all those in Malawi who helped make this possible, and I ask the media please to respect our privacy during this transitional time. πŸ™ Thank you also to my friends, family and my very large team for all your support and Love!"