The top Iraqi officer in Mosul, whose forces fled with hardly a fight as ISIS militants and their allies took over Iraq’s second-largest city, is an accused torturer who was once targeted by the U.S. military and the Iraqi criminal justice system.

That fact may help explain why the Iraqi security forces abandoned the city despite their superior arms and numbers and why large elements of Mosul’s Sunni population seemed to welcome a group as notoriously brutal as ISIS. Most importantly, it explains much of the hostility and distrust Iraq’s Sunni population feels toward the government in Baghdad, and why, at this stage, the reunification of Iraq will be so difficult to achieve.

Tuesday, Iraqi Prime Minster Nuri Al Maliki fired Staff Lieutenant General Mahdi Al Gharawi, relieving him of command of Nineveh province, the area where Mosul is located that is now largely under ISIS control. The prime minister also ordered that the general and his immediate subordinates face criminal charges for abandoning their posts. It’s a strange turn, because it was Maliki who decided to appoint Al Gharawi to the position in the first place over the strenuous objections of U.S. advisers and the Iraqi justice system.

After being investigated for years, Al Gharawi was charged by an Iraqi court in 2008, accused of running secret prisons and systematically torturing detainees when he was commander of the 2nd National Police Division in Baghdad. According to testimony collected from Al Gharawi’s victims and from officers who had served under him, “he ordered savage beatings and watched as interrogators brutalized detainees.” As Time Magazine reported in 2008, “some witnesses told the task force that Al Gharawi personally took part in torture in other instances.”

The charges against Al Gharawi played out against a backdrop of increasing sectarian violence in Iraq. From 2006 to 2008 Iraq was on the brink of civil war. The violence was spurred on by vicious attacks on Shia civilians, led by ISIS’ predecessor, Al Qaeda in Iraq, while Shia militias and sectarian death squads that often included members of the government’s security forces also tortured and killed Sunni civilians indiscriminately.

From 2006 to 2008, U.S. military lawyers and commanders pressed Maliki to support sending Al Gharawi to trial, to prove he was serious about weeding out sectarianism in the ranks of his security forces. Those efforts failed. A 2006 diplomatic cable released by wikileaks shows then-U.S. Ambassador Zalmay Khalilizad explaining Maliki’s intransigence. “Mahdi has proven valuable enough to Maliki,” Khalilizad wrote, “that he rebuffed our request that he execute an Iraqi warrant for Mahdi’s arrest.”

A unit called the Major Crimes Task Force, consisting of both American and Iraqi lawyers and investigators, built a strong case against Mahdi. The unit compiled dozens of witness statements about his participation in the systematic torture of detainees along sectarian lines at the height of the violence between Sunni and Shia factions in Iraq in 2005 and 2006. (In 2007, as an American officer in Baghdad, I assisted the Major Crimes Task Force in their efforts to pursue General Mahdi’s arrest and trial.) This investigation augmented a previous Iraqi warrant from 2006. Twenty brave witnesses delivered statements that he ordered the systematic torture of detainees and often supervised it himself.

In an excerpt of that confidential cable dated the 7th of August 2006, Khalilizad discusses the government’s arrest of security force members being charged with violent criminal acts—war crimes, essentially:

“Mahdi is alleged to have committed gross human rights violations and extra-judicial killings during his service as the National Police’s Second Division Commander at the detention facility known as Site 4. Mahdi has proven valuable enough to Maliki, however, that he rebuffed our request that he execute an Iraqi warrant for Mahdi’s arrest. MoI Bulani has also been unhelpful on this issue. He has told us that Mahdi was absolved of allegations against him pursuant to Section 134B of the Iraqi Criminal Code that allows a Minister to block the implementation of an arrest warrant if the suspected individual is conducting the official duties of his office.”

The cable offers a firsthand insight into Maliki’s priorities at the time—concentrating authority and instilling sectarianism in the Iraqi Security Forces. In fact, the Iraqi government would drag its feet on arresting General Mahdi for another two years before finally refusing once and for all.

Ironically, it was an Iraqi legal code intended to prevent sectarian targeting that the Maliki government used to help Al Gharawi escape justice through a loophole. According to an Iraqi statute, section 134B of the Iraqi Criminal Code, a minister can dismiss criminal charges against a member of his ministry to prevent the sectarian prosecution of his ministerial employees. It was not intended to protect police generals facing trials for the mass torture and execution of civilians but, perversely, that’s how it was applied in Al Gharawi’s case.

Heated exchanges followed between U.S. and Iraqi officials when Al Gharawi’s charges were dropped. Both U.S. Ambassador Crocker and General Petraeus tried to convince the Iraqi government that it had to show its skeptical Sunni citizens that a Shiite government was willing to arrest senior Shiite security officials for sectarian violence. Instead, the predominantly Shia government decided to let Al Gharawi go. Once the accused war criminal was free, the Iraqi government then put him in charge of the largest Sunni Arab majority city in the country, Mosul, where Al Qaeda was still actively resisting the government.

Even if Mahdi Al Gharawi was somehow innocent of all these charges, the message his appointment sent to the citizens of Nineveh province was unmistakable: that Maliki was not concerned about a Shiite general with this taint on his reputation being in charge of a Sunni province. And the U.S. is implicated too, as Al Gharawi assumed command in Nineveh before the U.S. withdrew from Iraq. How much the U.S. command at the time resisted this decision is unknown, but American memories in Iraq are notoriously short and it is entirely possible that many officers in 2011 were simply unaware of his unsavory reputation despite the fact that two successive American ambassadors in Iraq had campaigned for his arrest.

Even worse is that Human Rights Watch recommended his relief only a year ago for ongoing abuses committed under his command in Mosul.

The Human Rights Watch report from last year details a pattern of abuse in Al Gharawi’s 3rd Federal Police Division during 2012 and 2013. The report recounts the disappearance of a 15-year-old boy in police custody whose body was later found with large-caliber gunshot wounds, and an incident where Federal Police opened fire on peaceful protesters, killing one and injuring others.

By all indications, the general was operating exactly as he had in South Baghdad in 2005 and 2006, abusing and alienating the population.

It’s not a straight line from Al Gharawi’s release and later promotion in Nineveh to the ISIS takeover of Mosul, but the events are connected. Religious absolutists like ISIS may be beyond political persuasion but many of ISIS’ supporters are not. The non-religious fundamentalists in the Sunni coalition supporting ISIS may never have been receptive to the group if Maliki had governed inclusively and proved that he was willing to punish crimes committed by his Shia loyalists. Instead, a segment of Iraq’s Sunnis were driven into an alliance with ISIS, in no small part by the ruthless sectarian logic that the Baghdad government had embraced and the Al Gharawi exemplifies.

Now, while Iraq moves closer to the brink, we can only wonder how events in Mosul might have gone differently if Al Gharawi had been sent to the trial he was meant for years ago.