New infections with H.I.V. have dropped by half in the past decade in 25 poor and middle-income countries, many of them in Africa, the continent hardest hit by AIDS, the United Nations said Tuesday.

The greatest success has been in preventing mothers from infecting their babies, but focusing testing and treatment on high-risk groups like gay men, prostitutes and drug addicts has also paid dividends, said Michel Sidibé, the executive director of the agency U.N.AIDS.

“We are moving from despair to hope,” he said.

Despite the good news from those countries, the agency’s annual report showed that globally, progress is steady but slow. By the usual measure of whether the fight against AIDS is being won, it is still being lost: 2.5 million people became infected last year, while only 1.4 million received lifesaving treatment for the first time.

“There has been tremendous progress over the last decade, but we’re still not at the tipping point,” said Mitchell Warren, the executive director of AVAC, an advocacy group for AIDS prevention. “And the big issue, sadly, is money.”

Some regions, like Southern Africa and the Caribbean, are doing particularly well, while others, like Eastern Europe, Central Asia and the Middle East, are not. Globally, new infections are down 22 percent from 2001, when there were 3.2 million. Among newborns, they fell 40 percent, to 330,000 from 550,000.

The two most important financial forces in the fight, the multinational Global Fund for AIDS, Tuberculosis and Malaria and the domestic President’s Emergency Plan for AIDS Relief, were both created in the early 2000s and last year provided most of the $16.8 billion spent on the disease. But the need will soon be $24 billion a year, the groups said.

“Where is that money going to come from?” Mr. Warren asked.

The number of people living with H.I.V. rose to a new high of 34 million in 2011, while the number of deaths from AIDS was 1.7 million, down from a peak of 2.3 million in 2005. As more people get life-sustaining antiretroviral treatment, the number of people living with H.I.V. grows.

Globally, the number of people on antiretroviral drugs reached 8 million, up from 6.6 million in 2010. However, an additional 7 million are sick enough to need them. The situation is worse for children; 72 percent of those needing pediatric antiretrovirals do not get them.

Photo

A patient infected with H.I.V. cooled off from the heat in August at a treatment center on the outskirts of Yangon, Myanmar.Credit
Alexander F. Yuan/Associated Press

New infections fell most drastically since 2001 in Southern Africa — by 71 percent in Botswana, 58 percent in Zambia and 41 percent in South Africa, which has the world’s biggest epidemic.

But countries with drops greater than 50 percent were as geographically diverse as Barbados, Cambodia, the Dominican Republic, Ethiopia, India and Papua New Guinea.

The most important factor, Mr. Sidibé said, was not nationwide billboard campaigns to get people to use condoms or abstain from sex. Nor was it male circumcision, a practice becoming more common in Africa.

Rather, it was focusing treatment on high-risk groups. While saving babies is always politically popular, saving gay men, drug addicts and prostitutes is not, so presidents and religious leaders often had to be persuaded to help them. Much of Mr. Sidibé’s nearly four years in his post has been spent doing just that.

Many leaders are now taking “a more targeted, pragmatic approach,” he said, and are “not blocking people from services because of their status.”

Fast-growing epidemics are often found in countries that criminalize behavior. For example, homosexuality is illegal in many Muslim countries in the Middle East and North Africa, so gay and bisexual men, who get many of the new infections, cannot admit being at risk. The epidemics in Eastern Europe and Central Asia are driven by heroin, and in those countries, methadone treatment is sometimes illegal.

Getting people on antiretroviral drugs makes them 96 percent less likely to infect others, studies have found, so treating growing numbers of people with AIDS has also helped prevent new infections.

Ethiopia’s recruitment of 35,000 community health workers, who teach young people how to protect themselves, has also aided in prevention.

Mr. Sidibé acknowledged that persuading rich countries to keep donating money was a struggle. The Global Fund is just now emerging from a year of turbulence with a new executive director, and the American program has come under budget pressures. Also, he noted, many countries like South Africa and China are relying less on donors and are paying their own costs. The number of people on treatment in China jumped 50 percent in a single year.

Mr. Warren’s organization said in a report on Tuesday that the arsenal of prevention methods had expanded greatly since the days when the choice was abstain from sex, be faithful or use condoms. Male circumcision, which cuts infection risk by about 60 percent, a daily prophylactic pill for the uninfected and vaginal microbicides for women are in use or on the horizon, and countries need to use the ones suited to their epidemics, the report concluded.

A version of this article appears in print on November 21, 2012, on page A8 of the New York edition with the headline: New H.I.V. Cases Falling In Some Poor Nations, But Treatment Still Lags. Order Reprints|Today's Paper|Subscribe