California will become the first state to allow pharmacies to dispense HIV-prevention drugs over the counter, a move that supporters say is an important step toward ending the AIDS epidemic in the United States.

Under a new law, pharmacists who undergo special training will be able to provide 60-day supplies of pre-exposure prophylaxis, commonly called PrEP and sold under the brand name Truvada, as well as doses of post-exposure prophylaxis, or PEP, meant to be used in an emergency after possible exposure to the virus, without a doctor’s prescription. Studies have found that the drugs are very effective, but many people at high risk of infection do not take them.

“All Californians deserve access to PrEP and PEP, two treatments that have transformed our fight against HIV and AIDS,” said Gov. Gavin Newsom, who signed the bill into law Monday.

Federal data show that there are about 40,000 new HIV infections each year, and black and Latino men who have sex with men are at the greatest risk. In his State of the Union address in February, President Donald Trump vowed to stop the spread of HIV by 2030, and wider access to PrEP is a linchpin of that effort.

Some medical groups had initially opposed the bill because they were concerned that patients could take Truvada long term without medical supervision. In a compromise, the bill was revised to guarantee a maximum of 60 days of PrEP treatment without a doctor’s prescription. After that, a prescription is needed.

The law also specifies that patients must show proof that they have tested negative for HIV in the previous seven days before they can be provided with the preventive drugs.

According to Morgan Carvajal, a legislative advocate at the California Medical Association, it is crucial to test for HIV before starting PrEP or PEP. If a patient who has HIV takes those drugs, she said, the virus can become resistant to key ingredients that are also found in medicines used to treat the virus. That could limit a patient’s treatment options down the road. She added that regular medical checkups for PrEP users are also essential to check renal function every six months.