BAGHDAD, Feb 6 (Reuters) - Iraqi authorities are detaining thousands of women illegally and subjecting many to torture and ill-treatment, including the threat of sexual abuse, Human Rights Watch said in a report published on Thursday.

Many women were detained for months or even years without charge before seeing a judge, HRW said, and security forces often questioned them about their male relatives' activities rather than crimes in which they themselves were implicated.

In custody, women described being kicked, slapped, hung upside-down and beaten on the soles of their feet, given electric shocks, threatened with sexual assault by security forces during interrogation, and even raped in front of their relatives and children.

"The abuses of women we documented are in many ways at the heart of the current crisis in Iraq," said HRW's deputy Middle East and North Africa director Joe Stork in a statement accompanying the report, titled: "'No One Is Safe': Abuses of Women in Iraq's Criminal Justice System."

"These abuses have caused a deep-seated anger and lack of trust between Iraq's diverse communities and security forces, and all Iraqis are paying the price."

A spokesman for Iraq's Human Rights Ministry said the testimonies in the HRW report were "over-exaggerated," but acknowledged that "we have some limited illegal behaviors which were practiced by security forces against women prisoners," which it said had been identified by the ministry's own teams.

These teams had referred their reports to the relevant authorities, "asking them to bring those who are responsible for mistreating female detainees to justice," the spokesman said.

"Iraq is still working to put an end to prison abuse and, with more time, understanding of law and patience, such illegal practices will become a history," he said.

The 105-page report is based on interviews with imprisoned Sunni and Shi'ite women and girls, although Sunnis make up the vast majority of the more than 4,200 women detained in Interior and Defense Ministry facilities, HRW said.

The release of women detainees was a main demand of Sunnis who began demonstrating late in 2012 against the Shi'ite-led government, which they accuse of marginalizing their community.

Security forces cleared one of two Sunni protest camps in Anbar province in December 2013. In the ensuing backlash, militants seized the city of Falluja and parts of Ramadi.

Since then, more than 1,000 people have been killed across Iraq, according to Iraq Body Count, and the army is preparing for a possible ground assault to retake Falluja.

One woman who entered her meeting with HRW at a death row facility in Baghdad on crutches said she had been permanently disabled by abuse, displaying injuries consistent with the mistreatment she alleged.

Seven months later, she was executed despite lower court rulings that dismissed charges against her following a medical report that supported her accusations of torture.

HRW described Iraq's judiciary as weak and plagued by corruption, with convictions frequently based on coerced confessions, and trial proceedings that fall far short of international standards.

If women are released unharmed, they are frequently stigmatized by their family or community, who perceive them to have been dishonored, HRW said.

"Both men and women suffer from the severe flaws of the criminal justice system. But women suffer a double burden due to their second-class status in Iraqi society," HRW said. (Additional reporting by Ahmed Rasheed; Writing by Isabel Coles; Editing by Alistair Lyon)