A parliamentary task force finalized the bill in November, and lawmakers approved it on Tuesday.
A copy of the revised penal code obtained by The Associated Press includes several amendments that make sex outside of marriage punishable by one year in prison and cohabitation by six months.
However, charges of adultery must be based on a report filed with the police by the spouse, parent or child.
It also said it was illegal to promote contraception and religious blasphemy, and reinstated a ban on insulting the sitting president and vice president, state institutions and national ideology.
The law maintains that abortion is a crime, but it adds exceptions for women with life-threatening medical conditions and rape survivors if the fetus is less than 12 weeks old, in line with what was already laid out in the Medical Practice Act 2004.
Rights groups have criticized some of the proposed amendments as being too broad or vague, and have warned that their haste into the new penal code could punish normal activity and threaten free expression and privacy rights.
However, some supporters hailed it as a victory for the country’s LGBTQ minority.
Lawmakers finally agreed in a heated deliberation session to repeal a provision proposed by Islamist groups that made homosexuality illegal.
The code would also preserve the death penalty in the criminal justice system, despite calls by the National Human Rights Commission and other groups to abolish the death penalty, as dozens of other countries have done.
A previous bill was due to be passed in 2019, but President Joko Widodo urged lawmakers to delay a vote on the bill amid growing public criticism, leading to nationwide protests that saw tens of thousands take to the streets street.