JAKARTA, Indonesia — The Indonesian president, Joko Widodo, signed a decree on Wednesday authorizing chemical castration for convicted child sex offenders and requiring those released on parole to wear electronic monitoring devices.

The new punishment comes in response to the brutal gang rape and murder in April of a 14-year-old girl on her way home on the island of Sumatra. Seven teenage boys were each sentenced to 10 years in prison for the crime, which prompted national outrage and revived previous calls for chemical castration as a punishment against child sex offenders.

Mr. Joko told a news conference at the presidential palace in Jakarta, the Indonesian capital, that he had signed a decree amending the country’s 2002 law on child protection to enable judges to hand down the punishment at their discretion.

“The inclusion of such an amendment will provide space for the judge to decide severe punishments as a deterrent effect on perpetrators,” Mr. Joko said.