"In my opinion, this would completely remove (Madonna) from the definition of 'resident,'" the judge said.
There was nothing else in the ruling to hint at criticism of Madonna, and anti-foreigner sentiment also does not appear to have played a role. Comment from the judge that foreign adoption should not be ruled out but should be the last option was consistent with international treaties on adoption.
Critics had accused Madonna of using her fame and money to fast-track the adoption, but the singer said she had followed standard procedures. She faced similar allegations when she brought home David, who is now 3.
Mavuto Bamusi, an official with Malawi's Human Rights Consultative Committee, called Friday's ruling "a defining moment for child protection." Bamusi's group had been among those criticizing Madonna's adoption plans, saying they revealed weaknesses in the country's laws.
"We sympathize with children like Mercy who find themselves in orphanhood," Bamusi said. "But the Malawi authorities should take this as a moment of reflection. The laws of Malawi should now be strengthened so that no celebrity, no family that is trying to adopt should be seen as taking advantage of our weak laws."
In court papers made public Friday, Madonna said Chifundo's grandmother was unable to care for her. Media in the country had reported that the grandmother had initially opposed the adoption but later agreed.
The girl's mother, according to the affidavit, died at age 14 not long after her baby was born Jan. 22, 2006. There was no mention of the father in the affidavit. The mother's brother is listed as having consented to the adoption.
Malawi's child welfare minister had endorsed Madonna's adoption application.
"We have close to 2 million orphans in Malawi who need help," Women and Child Welfare Development Minister Anna Kachikho told The Associated Press. "We can't look after all of them as a country. If people like Madonna adopt even one such orphan, it's one mouth less we have to feed."
Orphans usually are taken in by their extended families in Africa, but AIDS and other diseases have taken a toll on those who might have traditionally provided support. In villages across the continent, frail elderly grandmothers do their best to care for children, but many end up in orphanages or on the streets.
Malawi, with a population of 12 million, is among the poorest countries in the world, with rampant disease and hunger, aggravated by periodic droughts and crop failure.
The U.N. says 1 million Malawian children have lost one or both parents, about half of them to AIDS, and estimates 18 million African children will have lost a parent to AIDS by 2010.
Adoptions from Africa have risen in recent years, but the continent still accounts for only about 14 percent of overseas adoptions by Americans. According to the U.S. State Department, 2,399 visas were issued to African children adopted by Americans last year, out of 17,438 adoptions from abroad. Most of the African children were from Ethiopia. Malawi, perhaps because its laws on foreign adoptions are vague, has not been a source of many children.