The genetic diversity is a legacy of its foreign aid. Since the 1960s, Cuba has sent abroad thousands of “internationalists” — soldiers, doctors, teachers and engineers. Stationed all over Africa, they brought back a wide array of strains. According to a study in 2002, 11 of Cuba’s 21 strains are unknown elsewhere, formed when two others mixed.

And Cuba’s success has come despite its being a sex tourism destination for Europeans and Canadians.

While the police enforce laws against overt streetwalking, bars and hotel lobbies in downtown Havana are filled with young women known as jineteras — slang for “jockeys” — who approach foreigners, asking if they would like to go for a drink, or perhaps dancing, with the unspoken assumption that it will lead to more. Even so, of the roughly 1,000 new infections diagnosed each year, 81 percent are among men and very few among young unmarried women.

“Most of those who sleep with tourists know to use condoms,” said Dr. Ribero Wong, an AIDS specialist here.

In a survey in 2009, 77 percent of all sex workers said they regularly used condoms.

There are male jineteras for gay tourists too, of course, “but we believe the main vector is within the people,” said Dr. Luis Estruch Rancaño, deputy minister for public health. “Mainly, the very promiscuous group in the homosexual community who have many partners and don’t take precautions.”

One example is Carlos Emilio García, 50, a registered nurse who lives and works at a former quarantine sanitarium outside Havana. He had negative H.I.V. tests at his job every six months from 1990 to 1996, but became infected in 1997.

He admits to having had many partners; as he put it, “No, I don’t know who my assassin is.”

Asked why a well-educated nurse would risk sex without a condom, he waved his hands in the air and replied, “You know — because we all do crazy things sometimes.”