The Supreme Court's decision was unanimous. (INDRANIL MUKHERJEE/AFP/Getty)

India has decriminalised gay sex in a momentous ruling.

The five judges of the Supreme Court were unanimous in their decision to overturn the ban on consensual same-sex relations, which was previously punishable by a sentence up to life in prison.

Since July, the court has been hearing testimonies from celebrities and numerous petitions arguing for gay sex between consenting adults to be legalised.

In his judgment, the Chief Justice of India, Dipak Misra, said: “Any consensual sexual relationship between two consenting adults – homosexuals, heterosexuals or lesbians – cannot be said to be unconstitutional,” according to Reuters.

With the exception of the years between 2009 and 2013, gay sex has been illegal in India since the introduction of Section 377 in 1861.

The law, made under British colonial rule, banned sexual activity “against the order of nature,” including with another man or woman.

The controversial legislation has been widely used to clamp down on the LGBT+ community in India, which is home to 1.3 billion people.

In 2009, the High Court in Delhi ruled that the 1861 law violated human rights, and legalised homosexual sex between consenting adults.

But just four years later, the Supreme Court reversed the High Court ruling, making gay sex illegal again and outraging LGBT+ rights campaigners across the world.

Activists and supporters have welcomed the decision, with Meenakshi Ganguly, the South Asia director for Human Rights Watch, tweeting: “Thanks to all that fought for this, braving the worst sort of prejudice.

“This is a good day for human rights.”

Indian actress Preity Zinta wrote: “‘If you have a heart you should be free to love who you want.’ ❤️ So Happy to hear that the Supreme Court of India has abolished #section377 decriminalising Homosexuality.”

Another famous actress, Sonam Kapoor Ahuja, tweeted: “This is the india I want to live in. Not one filled with hate, bigotry,sexism homophobia and intolerance.

“THIS is the India I love. ”

The United Nations in India welcomed the ruling, adding that it “sincerely hopes that the court’s ruling will be the first step towards guaranteeing the full range of fundamental rights to LGBTI persons.”

“We also hope that the judgment will boost efforts to eliminate stigma and discrimination against LGBTI persons in all areas of social, economic, cultural and political activity, thereby ensuring a truly inclusive society,” the UN said.

“The focus must now be on ensuring access to justice, including remedy; effective investigations of acts of violence and discrimination; and effective access to economic, social and cultural rights.”