Dec 6: It is part of a raft of changes that critics say erode political freedom.
The new criminal code will not come into effect for another three years and also includes a ban on insulting the president and expressing views that run counter to state ideology.
Small groups held protests outside the parliament in Jakarta this week.
The code - which will apply to both Indonesians and foreigners - includes several "morality" laws and makes it illegal for unmarried couples to live together and have sex.
A person's partner or parents can report them for the offence of having sex outside of marriage. Adultery will also be an offence for which people can be jailed.
However the new criminal code also affects other areas of public life and rights groups say it amounts to a crackdown on democratic rights.
The new code includes defamation articles that make it illegal for people to insult the president or express opinions against the national ideology.
But legislators said there were in-built defences for free speech and protests made in the "public interest".
They also praised the achievement of passing a new criminal code, one which had not been thoroughly revised since Indonesia became independent from Dutch rule.
A previous draft of the code was set to be passed in 2019 but sparked nationwide protests with tens of thousands taking part in demonstrations.
Many, including students, took to the streets and there were clashes with police in the capital Jakarta.
Some parts of Indonesia already have strict religion-based laws on sex and relationships.
The province of Aceh enforces strict Islamic law and has punished people for gambling, drinking alcohol and meeting members of the opposite sex.