India's Supreme Court has closed a loophole in the country's age of consent law that made it legal for men to have sex with girls as young as 15 provided they were married.

The landmark ruling threw out the exception that judged sex with a girl below the age of 18 to be illegal, but legal in cases where the girl, aged 15-18, is married.

This meant that boys aged 17 were being prosecuted for having sex with girls their own age, while older men escaped a statutory rape charge because they were married to adolescent wives.

"We are left with absolutely no other option but to harmonise the system of laws relating to children," the Supreme Court's Justice Madan Lokur said in his decision.

Independent Thought, an NGO based in the province of Uttar Pradesh, brought the case before the Supreme Court despite successive Indian governments excusing the exception by citing the country's unique social and economic factors.

A recent census by India Spend, a data journalism initiative, estimated that nearly 12 million children under the age of 10 are married. Among them, as many as 5.4 million are said to be illiterate and 80 percent of them female.

In the years 2008 and 2014, some 47 percent of girls in the country were married before their 18th birthday. This, while almost 20 percent were not older than 15, according to the UN's children agency UNICEF.

"We strongly feel that this decision of the Supreme Court will work in impacting child marriages, also," Jagmati Sangwan, women's activist and member of the All India Democratic Women's Association (AIDWA) told Al Jazeera.

The Supreme Court judges, however, declined to rule on another case challenging the law governing marital rape.

India does not recognize marital rape as an offense.This comes despite repeated efforts by activists to introduce a law making it illegal in recent times.

Rape is a frequent occurrence in India, with at least 34,651 reported cases in 2015, according to the figures from the National Crime Records Bureau cited by Al Jazeera.

The issue of sexual violence against women in India leapt to international prominence in December 2012 when a young woman was gang-raped on a bus in New Delhi.

Her subsequent death sparked mass protests across the country, prompting the government to raise its mandatory minimum jail sentence for rape from 10 to 20 years.