Madonna Adoption Could Have Been Derailed Over Rocco Custody Fight

2/13/2017 1:00 AM PST

Madonna Adoption Could Have Been Derailed Over Rocco Custody Fight

EXCLUSIVE

Madonna had multiple good reasons to end her custody war over Rocco ... if she didn't, her bid to adopt two kids from Malawi would have come to a grinding halt.

The judge who green lit Madonna's adoption last week spent a long time understanding the circumstances surrounding her custody dispute with ex-hubby Guy Ritchie ... so says an official from the Malawi courts. We're told the dispute was of "paramount concern" because the judge didn't want the adopted kids thrown into a "toxic" family environment.

Since the case settled and all seemed copacetic with Guy, the judge gave the thumbs-up.

As we reported, Rocco bailed on Madonna a year ago during her tour and moved to London to be with Guy. Rocco now spends the school year in London and summers in NYC.

A court-appointed guardian will travel to the U.S. and evaluate the family dynamic before the adoption's finalized.