Tunisia will finally ban forced anal examinations of men the authorities suspect of being homosexuals, the country's minister for human rights said.

Homosexuality is illegal in the North African state, carrying a prison sentence of up to three years. Now, the practice of forcing men to undergo an anal examination is due to end, although homosexuality will remain illegal.

“These exams can no longer be imposed by force, physical or moral, or without the consent of the person concerned,” Mehdi Ben Gharbia told AFP.

Gay Muslim marriages ‘thriving’ in Britain, says drag queen. https://t.co/stTxx3s6Xr — RT UK (@RTUKnews) July 19, 2017

Human rights groups have long called for an end to the examinations, labeling them as “cruel” and “inhuman.”

The invasive tests usually involve doctors “forcibly inserting their fingers, and sometimes other objects” into the anus of the accused, according to Human Rights Watch (HRW).

The NGO says the exams stem from discredited 19th-century theories that “homosexuals can be identified by the tone of the anal sphincter or the shape of the anus.”

Woman granted ‘humanitarian’ residency in New Zealand after years of abuse in UK. https://t.co/6bV3h0SDlH — RT UK (@RTUKnews) September 21, 2017

In April, the National Council of the Medical Order in Tunisia issued a statement calling on doctors to cease conducting the exams.

It appears their message has gotten through to those in power, though judges can still request that suspected homosexuals undergo the test. The accused can now refuse, however.

“That person has every right to refuse, without his refusal being held up as proof of homosexuality,” Gharbia said, adding that Tunisia is “committed to protecting the sexual minority from any form of stigmatisation, discrimination and violence.”

Tunisia is one of several countries documented by HRW that carried out forced anal exams over the last six years, the others being Cameroon, Egypt, Kenya, Lebanon, Tunisia, Turkmenistan, Uganda, and Zambia.