Aggressive efforts to end transmission of HIV are paying off in San Francisco, where public health officials are reporting record-low new cases, and the city is far outpacing national trends that show much narrower declines.

But at both the local and national level, disparities among age, race and gender groups are becoming more pronounced. Inequalities exist among those groups in the number of new cases and also in how quickly people who are newly diagnosed are able to access care and get the infection under control.

“We’ve had a really steep decline in new diagnoses. We’re down to 221 (new cases in 2017), which is the lowest number ever reported in San Francisco. That’s good news and we all need to celebrate that,” said Susan Scheer, director of HIV epidemiology and surveillance for the San Francisco Department of Public Health. “But we identified particular groups that are not making as much headway. That’s where the focus has shifted.”

San Francisco’s annual report on HIV and AIDS, released this month, showed 15,952 people living with HIV in the city in 2017. Nearly two-thirds are age 50 or older, and 22 percent are age 60 or older. The bulk of older people living with HIV are gay men who have been infected for 20 or more years and whose health needs stretch beyond just keeping the infection under control.

But since 2014, much of San Francisco’s public health attention has been on programs to end transmission of HIV, which are focused on young people who are most at risk of being infected. More than 60 percent of the 221 new diagnoses in the city in 2017 were in people younger than 40.

The total number of new cases was down 5 percent from the previous year and nearly 60 percent from a decade ago. At the peak of the AIDS epidemic in the late 1980s and early ’90s, more than 2,000 people were being diagnosed in San Francisco every year.

Diagnoses have been falling nationally, too, though not quite as dramatically. There were 39,782 new cases in the U.S. in 2016, the most recent year for which national data is available. That’s only about a 5 percent drop over a decade, according to the U.S. Centers for Disease Control and Prevention.

Dr. Diane Havlir, chief of the division of HIV/AIDS at San Francisco General Hospital, said San Francisco often is held up as a model of treatment and prevention of HIV, and global public health leaders are watching the city’s efforts to end transmission.

“They’re looking to San Francisco for this road map, and I’m so proud of this city,” she said. “But we’ve got some big challenges ahead. If we’re going to get close to zero, we have our work cut out for us.”

Of concern is that new diagnoses both locally and nationally have remained flat or have even increased among certain high-risk groups of people. They’ve climbed more than 10 percent among American Indian and Asian men who have sex with men in the U.S.

In San Francisco, rates rose last year among all black men and women. Rates among black men are almost triple that of white men, and eight times higher for black women compared with white women, according to the city’s new HIV report.

Early reports of increased participation in prevention programs among black men hopefully will pay off with reduced transmission rates in the near future, said Joe Hollendoner, chief executive of the San Francisco AIDS Foundation, who is involved in a citywide effort to end transmission of HIV.

Specifically, more black men who have sex with men are employing PrEP, or pre-exposure prophylaxis, which is a drug regimen that, when followed daily, dramatically reduces the chance of becoming infected with HIV.

“The more we make PrEP accessible, the more we’ll see declining rates in the future,” Hollendoner said.

San Francisco began its “Getting to Zero” campaign in 2014, with the goal of reaching near-zero new HIV infections by 2020. A cornerstone of the program is early diagnosis of new cases and rapid connection to medical care. The idea is that people who are treated for HIV can reduce their viral load — the amount of virus that is detectable in their blood — to nearly zero, making it almost impossible for them to infect others.

So far, the efforts seem to have paid off with the largest group of people affected by HIV: men who have sex with men. In 2017, 85 percent of these men were linked to medical care within a month of being diagnosed, and 86 percent were “virally suppressed” within a year. The number of new infections in this group has fallen sharply over the past decade.

But other at-risk groups — in particular, homeless people — have been more difficult to reach. Less than a third of homeless people with HIV are virally suppressed. And according to surveys of patients in San Francisco General Hospital’s HIV department, Ward 86, viral suppression worsens with degrees of housing instability. In other words, people who are living on the streets are far less likely to be virally suppressed than those who are living in homeless shelters or couch-surfing with friends.

The reason for the low viral suppression rates are varied and depressingly simple, public health officials say. Many people who are homeless also suffer from mental health and drug use problems that make them less able to stick with a treatment plan. Sometimes the drugs they take to treat HIV are stolen on the streets or in shelters. They may have a hard time making it to medical appointments.

“We can do outreach and get people programs, but at the end of the day, we need housing for people,” said Dr. Susan Buchbinder, director of HIV research for the San Francisco Department of Public Health. “It’s very hard when you’re living such a challenging lifestyle to be virally suppressed.”

Erin Allday is a San Francisco Chronicle staff writer. Email: eallday@sfchronicle.com Twitter: @erinallday