The battered body of the victim was discovered, naked and tied up, in a forest on the island of Sumatra after she was attacked by a group of teenagers in April. Seven offenders have been jailed for 10 years.
"Sexual violence against children, as I have said, is an extraordinary crime," President Joko Widodo told journalists, according to a statement.
"We hope that this law will be a deterrent for offenders and can suppress sexual crimes against children," Widodo said, also tweeting the news on his official account.
Chemical castration is the use of drugs to reduce libido or sexual activity. It is a legal form of punishment in South Korea, Poland and the Czech Republic, as well as in some U.S. and Australian states.
Convicted pedophiles who have served jail sentences could also be forced to wear ankle monitors so that authorities can trace their movements.
The law is effective immediately, although Indonesia's parliament has the power to overturn it or demand revisions.
"These acts threaten and endanger children, and they destroy the lives and development of children for the future," the president's statement said.
The law was drafted to address a significant increase in cases of sexual violence against children, Widodo said, although he gave no statistics to illustrate an increase.
The country has long struggled with a high incidence of sexual violence, and several cases have been reported recently.
Earlier this month, a woman was raped and murdered by three men on the outskirts of the Indonesian capital, Jakarta.
The case of the 14-year-old girl in Indonesia has drawn comparisons to the horrific gang rape and murder of a 23-year-old medical studen
t in New Delhi in 2012, which triggered protests and led to tougher laws against sexual assault.
Widodo was elected in 2014 and was seen as a promising figure for reform in the Southeast Asian nation of 250 million people.
But he drew international criticism last year when he rejected appeals for clemency and green-lighted the execution of 13 drug traffickers
, many of them foreigners, by firing squad. He also had authorized the executions of a group before them, ending a four-year period in which the country appeared to be cooling on capital punishment. Indonesia is again preparing to carry out a fresh round of executions.