That includes the HPV vaccines Gardasil and Ceravix, which help prevent many strains of cervical cancer.
Gov. Jerry Brown announced on Sunday that he had signed AB499 into law.
"It's always a close question as to what we might allow. But we do that with other reproductive kinds of issues, and I felt this one was similar to what we've done before," Brown said.
The human papilloma virus is the world's second-leading cause of cancer deaths among women.
The governor's signature touched off a firestorm, with critics saying it intrudes on parental rights.
The Masinas family likes the availability of an anti-cancer vaccine but doesn't like the government encouraging kids to go behind their parents' backs.
"I think the parents should be involved in that decision. I don't agree with as young as 12 without parental permission," said Beverly Masinas.
Social conservatives are angry that taxpayer money could be used to pay for the series of three shots over several months that could cost up to $500 per child.
"If her parents aren't aware of it, she will be emancipated, and the state will be paying for every single minor that's encouraged to go into a clinic and get these three different boosters," said Karen England of Capitol Resources Institute.
But Dr. Jacob Lalezari, a lead investigator in HPV research, says the debate shouldn't center around moral or ethical grounds, but on the benefits. It's most effective when it's given before a girl is sexually active.
"That their daughters might be engaging in sexual activity should not be a reason to prevent the vast majority of young women from having access to a vaccine that could essentially save their lives," Lalezari said.
Cervical cancer survivor Marlene Von Friederichs-Fitzwater said she doesn't wish anyone to go through what she did.
"I would urge anyone that's eligible to have the vaccine, absolutely much better than going through the disease," she said.
In addition to the HPV vaccine, the law also allows 12-year-olds to get other STD prevention treatments, including hepatitis shots and medications to reduce the risk of HIV infection after exposure.
AB499 was one of more than 100 bills Brown had to sign or veto before a midnight deadline.