The law was approved on March 6 and will become effective starting July 1.
The new law states pedophiles will be chemically castrated, while courts will rule separately on those found guilty of rape.
The law also applies to foreign nationals.
Liberal Party lawmaker Valeriu Munteanu, who authored the measure, said it was necessary after public outrage over several pedophile cases involving U.S. and West European nationals.
The law says the procedure is to be applied only to those convicts who are in the final three months of their sentence, in order to give maximum time to any necessary judicial review.
The procedure involves testosterone-suppressing hormones that are administrated once every three months.