Indonesia's parliament approved Tuesday legislation that would outlaw pre-marital sex while making other sweeping changes to the criminal code -- a move critics deemed as a setback to the country's freedoms.

After the controversial new criminal code received the majority of votes from lawmakers during the plenary session, deputy house speaker Sufmi Dasco Ahmad banged the gavel to signal the text was approved and shouted "legal".

Rights groups had protested against the amendments, denouncing a crackdown on civil liberties and a shift towards fundamentalism in the world's most populous Muslim-majority nation.

"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.

Some of the most controversial articles in the newly passed code are criminalising premarital and extra-marital sex, as well as the cohabitation of unmarried couples.

There are also fears these rules could have a major impact on the LGBTQ community in Indonesia where gay marriage is not allowed.

The spokesperson of the Law and Human Rights Ministry's criminal code bill dissemination team, Albert Aries, defended the amendments before the vote and said the law would protect marriage institutions.

He said acts of pre-marital and extra-marital sex could only be reported by a spouse, parents or children, limiting the scope of the amendment.

But rights groups slammed the legislation as morality policing and activists denounced it as a crackdown on civil and political freedoms.

A revision of Indonesia's criminal code, which stretches back to the Dutch colonial era, has been debated for decades.

Rights groups say the proposals underscore a growing shift towards fundamentalism in a country long hailed for its religious tolerance, with secularism enshrined in its constitution.

"We are going backward... repressive laws should have been abolished but the bill shows that the arguments of scholars abroad are true, that our democracy is indisputably in decline," Amnesty International Indonesia director Usman Hamid told AFP.

About a hundred people protested against the bill Monday and unfurled a yellow banner that read "reject the passing of the criminal code revision", with some dropping flower petals on the banner as is done for a funeral.

Abdul Ghofar, a campaigner of Indonesia’s environmental group WALHI, said the symbolic acts signified the public’s “grief” over the impending passage of the revision.

Another protest to reject the new law is scheduled to be held on Tuesday in front of the parliament building.