Parliament of Indonesia has approved a new criminal code that will make sex outside of marriage punishable by up to a year in prison.

It is part of a raft of changes that critics say erode people’s rights.

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, which will apply to both Indonesians and foreigners, includes several “morality” laws which make it illegal for unmarried couples to live together and have sex.

Rights groups say this disproportionately affects women, LGBT people and ethnic minorities in the country.

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.

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.

Insulting president illegal

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 defences for free speech and protests made in the “public interest”.

Still, 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.

He added that research from Gulf states, where there are similar laws governing sex and relationships, showed women were punished and targeted by such morality laws more than men.

Indonesia is not a secular state. Atheism is unacceptable – technically you need to follow one of five prescribed religions. So it is a multi-religious state with an official ideology, Pancasila, which prioritises no faith over any other. That was Indonesia’s post-independence leader Sukarno’s idea, to discourage large parts of the archipelago where Muslims are not a majority from breaking away.

But since the fall of Suharto – who ruthlessly suppressed political Islamic groups – there has been growing mobilisation around Islamic values, the sense that Islam is threatened by outside influences and more conservatism in many areas of the island of Java, where more than half of Indonesians live. Political parties have responded to this and demanded tougher laws to police morals.

Current leader Jokowi is from the syncretic Javanese tradition that adheres to a more flexible form of Islam, but his main preoccupation is his legacy of economic development rather than tolerance and liberal values.

He has shown, for example in the jailing of former Jakarta governor Ahok on blasphemy charges, that he’s willing to give hardline Muslims some of what they want.

Indonesia is home to several religions but the majority of its 267 million people are Muslim.

Since the country’s democratic transition in 1998, it follows a creed known as Pancasila, which does not prioritise any faith but does not accept atheism. However, local law in many areas of the country is informed 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.