A long-acting drug injected every two months is more effective at preventing HIV than the pills most commonly used by people at risk of acquiring the infection, according to research released Tuesday at an international AIDS conference.

The drug cabotegravir was tested on more than 4,500 cisgender men who have sex with men and transgender women who have sex with men in 43 countries. While Truvada, the pill used most often to block the virus, is also highly effective, the injectable drug proved to be even better, the research shows.

Perhaps more important, an injection every two months may allow more people to remain on medication, known as “pre-exposure prophylaxis” or PrEP, that blocks the virus. People whose medical care is inconsistent, including homeless people, intravenous drug users and others in unstable situations, have trouble remaining on the daily pills. Others are reluctant to obtain them because of the stigma still associated with HIV.

“Giving individuals an option of an injection every eight weeks instead of taking a daily pill to prevent HIV provides choices and flexibility,” Monica Gandhi, San Francisco co-chair of the AIDS 2020 conference, said in an email. The worldwide conference is taking place online this week.

Truvada and Descovy, both manufactured by Gilead Sciences, are the only PrEP drugs approved by the Food and Drug Administration on the market. A generic form of Truvada is expected soon; Gilead has been a target of activist groups for setting high prices for its drugs.

The injectable drug tested in the new study is made by ViiV Healthcare. Kimberly Smith, head of research and development for the company, said removing the burden of adhering to a daily drug regimen accounts for the injectable’s superior performance. Adherence to pills starts off strong in many men, she said, but wanes over time.

Overall, 52 people in the study contracted HIV over a little less than three years — 39 who were on daily pills and 13 who received the experimental injections. Test subjects were enrolled at 43 sites in the United States, Africa, Asia and Latin America.

“I believe [the result] is primarily driven by the fact that you don’t need to adhere to a regimen every day,” Smith said.

About 1.7 million people throughout the world became infected with HIV last year, a figure that experts say could be greatly reduced if more people had access to PrEP and stayed on it. Taken daily, the drug is more than 90 percent effective at preventing sexual transmission of the virus and more than 70 percent effective at blocking it among people who inject street drugs and share needles.

But in the United States, only about 10 to 20 percent of the 1.1 million people considered at risk of contracting HIV are on PrEP. A disproportionate number of those not on medication are black and Latino men who have sex with other men. The United States has launched a program that, in part, focuses on them in a bid to end the transmission of HIV by 2030.

Smith said the company made a point of enrolling African American men who have sex with men in the hope that good results would persuade that group to adopt the medication. Half the U.S. subjects in the study, 844 men overall, were in that category, she said.

“Black men who have sex with men did extremely well” in the trial, Smith said. “This is a message we can carry to that population.”