In another setback in the long quest to prevent H.I.V. infection, a trial in South Africa has been shut down because an experimental vaccine was not working, federal health officials announced on Monday.

The trial, which began in 2016, followed one in Thailand that ended in 2009. That vaccine offered only modest protection against infection. Experts argued over how much, but the vaccine was no more than 30 percent protective.

Nonetheless, it was the only vaccine that had appeared to work at all.

“We hoped this vaccine candidate would work — regrettably, it does not,” said Dr. Anthony S. Fauci, director of the National Institute for Allergy and Infectious Diseases, which conducted the trial.

“Research continues on other approaches to a safe and effective H.I.V. vaccine, which I still believe can be achieved,” he added.