Indonesia on Tuesday adopted a new criminal code that outlaws sex outside marriage and cohabitation, in changes that critics contend could undermine freedoms in the Southeast Asian nation. The new laws apply to Indonesians and foreigners alike and restore a ban on insulting the president, state institutions, or Indonesia's national ideology known as Pancasila. The new criminal code, which was passed unanimously by parliament, replaces a framework that had been in use since independence in 1946 and was a mix of Dutch law, customary law known as hukum adat, and modern Indonesian law. "We have tried our best to accommodate the important issues and different opinions which were debated. However, it is time for us to make a historical decision on the penal code amendment and to leave the colonial criminal code we inherited behind," Yasonna Laoly, minister of law and human rights, told parliament ahead of the vote. The new criminal code will not come into effect for another three years and also includes a ban on insulting the president and speaking out against state ideology. Protesters staged small rallies outside the parliament in Jakarta this week. The code includes several "morality" laws that make it illegal for unmarried couples to live together and have sex. A person's partner or parents can report them for the offense of having sex outside of marriage. Adultery will also be an offense for which people can be jailed. Rights activists say the new code also suppresses political expression and clamps down on religious freedom. There are now six blasphemy laws in the code, including apostasy — renouncing a religion. For the first time since its independence, Indonesia will make it illegal to persuade someone to be a non-believer. New defamation articles also make it illegal for people to insult the president or express opinions against the national ideology. However, legislators said they had added defenses for free speech and protests made in the "public interest". Human Rights Watch on Tuesday said the new code's provisions were a "disaster" for human rights. The rights group's Asia Director Elaine Pearson told the BBC it was a "huge setback for a country that has tried to portray itself as a modern Muslim democracy." The group's Jakarta-based researcher, Andreas Harsano, said there were millions of couples in Indonesia without marriage certificates ", especially among indigenous peoples or Muslims in rural areas" who had married in specific religious ceremonies. "These people will be theoretically breaking the law as living together could be punished up to six months in prison," he told the BBC. Indonesia is home to several religions but the majority of its 267 million people are Muslim. Since the country's democratic transition in 1998, Indonesia follows a creed known as Pancasila, which does not prioritize any faith but does not accept atheism. However, local law in many areas of the country is influenced by religious values. 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. Many Islamic civil groups in Indonesia have been pushing for more influence in shaping public policy in recent years. Lawmakers on Tuesday 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. — Agencies