A three-year effort to test for HIV in hospital emergency rooms, drug treatment centers, venereal disease clinics and other places with high-risk populations identified about 18,000 new infected people and enrolled three-quarters of them in treatment, federal officials said Thursday.

Although nationwide the campaign made only a small dent in the number of people who are infected but don’t know it — estimated to be as high as 240,000 — government officials nevertheless called it a success.

“This is a considerable boost to the nation’s health. Did it make a difference to America? I think it did,” said Jonathan Mermin, director of HIV/AIDS prevention at the federal Centers for Disease Control and Prevention.

The $111 million program was run in the 25 states and cities with highest HIV prevalence and included the District and Maryland. It especially targeted African Americans, who account for about half of new HIV infections in the United States each year.

In the District, the program diagnosed HIV in 1,669 people who hadn’t known they were infected. In Maryland, the number was 1,070. In both places, more than three-quarters of the people tested through the Expanded HIV Testing Initiative were black. The District and Maryland were in the top 10 places that were responsible for the most new cases.

About 1.2 million people in the United States are estimated to be infected with HIV, and about 20 percent of them don’t know it. About 55 percent of adults, and nearly 30 percent of those with a risk factor for HIV, have never been tested for the virus.

The people whose HIV was newly diagnosed benefit because many now have access to “life-prolonging treatment without which almost all would die,” Mermin said. The general population also benefits because people who know they are infected are less likely to transmit the virus than people who don’t know.

The testing initiative was created through a special appropriation from Congress after the CDC greatly loosened its guidelines for HIV testing in 2006. The agency said everyone age 13 to 64 should routinely be tested for HIV when they go to clinics or hospitals in places where 0.1 percent or more of the population has an undiagnosed infection. In the 25 targeted cities and states, the undiagnosed HIV prevalence was, on average, seven times higher than that.

In all, 2.8 million tests were performed, with 29,503 coming up positive. Of that total, 18,432 were people who didn’t know they were infected. Blacks accounted for 70 percent of the new diagnoses. Men accounted for nearly three-quarters of new diagnoses and were more than twice as likely to be HIV positive as the women tested.

About 90 percent of the tests occurred in a medical setting, including 30 percent in emergency rooms, 21 percent in sexually transmitted disease clinics, 17 percent in community health centers.

Community-based organizations, however, conducted about 10 percent of tests at nonmedical sites, and the chance of finding someone positive there was twice as high as elsewhere.

The failure of people to return for their test results and the failure of practitioners to refer those who do for medical treatment plagued earlier testing campaigns in high-risk populations.

In this one, 93 percent of people testing positive got their results; 78 percent were “linked to medical care,” and 83 percent were referred to services that helped them find and contact sexual partners.

In many hospitals and clinics, HIV tests are now part of the routine lab work when a person seeks care. Patients are told that the test will be done and given the chance to opt-out.

Previously, a person had to be individually counseled and sign a consent form acknowledging possible consequences of a positive test, including social stigma, family rejection and depression. With the arrival of triple-drug antiretroviral therapy, which is giving HIV patients near-normal life spans, many experts concluded that such special treatment was no longer necessary.

“It is the job of the health-care system to make HIV testing as routine as cholesterol screening,” Mermin said.

The testing program is being expanded to include 30 states and cities and will spend about $50 million a year in targeted testing, Mermin said. It will expand its focus to cover four populations: African Americans, Hispanics, injection-drug users and men who have sex with men. About 95 percent of people with AIDS in the United States fall into one of those groups.