The ruling followed an application by social workers in Camden, north London, who discovered that the baby was being breast-fed by her mother who is HIV-positive.
The baby's parents have refused to allow the baby to have a blood test, claiming that she is perfectly healthy and that they should be able to decide what is best for her.
But Camden social workers, who made the application under the Children Act, have argued that HIV is a deadly infection that could lead to Aids and kill the girl.
If found to be HIV-positive, the child could be treated with a combination of potentially life-saving drugs to combat the virus. If negative, her mother could be urged to stop breast-feeding in an attempt to prevent infection.
In his 90-minute judgment, Mr Justice Wilson said the case was about the rights of the baby and not the parents. Ordering a test to be done, he said the case for such a move was "overwhelming", although he conceded he could not order the mother to stop breast-feeding.
Social workers first became aware of the risk to the baby after a series of ante-natal care meetings between the parents and their doctor. The GP, who had only recently become the couple's doctor, became "gravely concerned" after reading the child's case notes, and passed on his worries to Camden Council's social services department. The 32-year-old unmarried mother, who was found to be HIV-positive in 1990 from a long-term relationship with another man, believes scientists are mistaken in seeing HIV as the sole cause of Aids. The child's father, an alternative healthcare practitioner aged 36, has tested negative for the virus.
After 1991 the mother stopped having blood tests and taking medication. She also developed doubts about the validity of generally accepted theories about HIV and Aids. She explored complementary therapies and concentrated on healthy eating and keeping fit.
The woman met the child's father in 1997. Before trying to have a baby the father underwent a test, which was negative. The woman became pregnant in July last year, and in April she had a natural water birth at home. The birth was uncomplicated and after a few minutes the mother began to breast-feed.
Simon White, Camden's director of social services, said after the judgment: "We have a legal duty to investigate a child's circumstances and decide whether we need to take action to safeguard or promote a child's welfare." Lawyers for the parents said they were considering an appeal.
The Terrence Higgins Trust, an Aids charity, backed the judge's decision, but some other groups did not. The International Forum for Accessible Science said the court had "undermined" parents' rights to make informed choices on behalf of their children.
After discovering the Aids risk to the baby, the family's GP arranged several meetingsaimed at reaching agreement over the ante-natal care. When none was forthcoming, Camden Council applied to the High Court for a Specific Issue Order.
The Terrence Higgins Trust said there have been 616 known cases of babies infected with HIV by their mothers - of whom 350 have developed Aids and 175 are known to have died.
Ethics debate, page 2Reuse content