Pharmaceutical giants dropped a lawsuit Thursday against a South African law that could provide cheaper AIDS drugs to millions of Africans — ending an international battle that deeply embarrassed the companies. 

The lawsuit over patent rights and profit was seen by human rights groups and AIDS activists as a landmark battle in the effort to secure medication for the 26 million people in Africa infected with HIV. The law could allow South Africa to import or make cheap generic versions of patented drugs. 

Activists who packed the Pretoria courtroom erupted into cheers and songs when Stephanus Cilliers, a lawyer for the 39 drug companies, told the judge that "the application is withdrawn." 

"There is no doubt that they have received a black eye," Mark Heywood of the group Treatment Action Campaign said of the companies, which include giants Merck, Bristol-Myers Squibb and Glaxo Wellcome. "And I think it will embolden people in developing countries around the world to stand up for medicines that are affordable." 

Manto Tshabalala-Msimang, the health minister, said South Africa had not agreed to any deals regarding the law, which passed but has not been implemented. The drug companies also agreed to pay all the costs of the case. 

But Tshabalala-Msimang implied the ruling did not mean the government planned to immediately begin providing otherwise expensive antiretroviral drugs to AIDS patients, saying it did not have the necessary infrastructure and also had some concerns about the drugs. 

The government also did not consider that the law gave it blanket authority to import or produce generic versions of the antiretroviral drugs, she said. 

The lawsuit has opened the drug companies to broad criticism since it began six weeks ago. Many have responded by drastically cutting prices on their own. But even with the severe price reductions offered by some companies, the vast majority of people suffering in Africa could not afford the medications. 

Tshabalala-Msimang said South Africa had not agreed to any deals regarding the law, which passed but has not been implemented. The drug companies also agreed to pay all the costs of the case. 

Mirryena Deeb, chief executive of the country's Pharmaceutical Manufacturers Association, said the suit was dropped as a "result of a negotiating process." She said the government had agreed to consult the companies when they draft the regulations to implement the law. 

"We are very pleased that we have found a way out of this impasse," Deeb said. 

In a statement issued in Geneva, the International Federation of Pharmaceutical Manufacturers Associations welcomed the settlement, saying the agreement balanced the health needs with respect for intellectual property rights. 

"Both the South African government and the industry agree that intellectual property protection is an essential incentive for innovation, not an obstacle to access," the federation said. "This agreement ensures that with strong intellectual property protection, consistent with international agreements, the search for new medicines will continue unabated." 

The 39 pharmaceutical companies that brought the suit argued that a 1997 South African law regulating medicines was too broad and unfairly targeted drug manufacturers. 

The government, AIDS activists and human rights groups have said the drug companies are trying to wring profits out of a public health nightmare that threatens to devastate South Africa and dozens of other impoverished countries. 

More than 25 million of the 36 million people infected with HIV live in sub-Saharan Africa, one of the world's most impoverished regions. In 2000, 2.4 million people in the region died from the effects of AIDS.