The U.S. pop star, who lives much of the year in England, began adoption proceedings in October 2006. She was granted temporary custody of David when he was 13 months old.
David had been placed in an orphanage by his father, Yohane, after the boy's mother died of an AIDS-related illness when he was a month old.
"We are very happy with what the judge has ruled," the BBC said attorney Alan Chinula told reporters outside the courthouse in Lilongwe. "It is a positive and beautiful judgment that will have an impact on Malawi's adoption laws. Finally the court has granted Madonna full adoption rights of the boy -- it's a long judgment but I am quite happy with it."
The BBC said Madonna was not in court when the ruling was read.