By Ned Parker, Isabel Coles and Raheem Salman

BAGHDAD (Reuters) - Lieutenant General Mahdi Gharawi knew an attack was coming.

In late May, Iraqi security forces arrested seven members of militant group Islamic State in Mosul and learned the group planned an offensive on the city in early June. Gharawi, the operational commander of Nineveh province, of which Mosul is the capital, asked Prime Minister Nuri al-Maliki's most trusted commanders for reinforcements.

With Iraq's military overstretched, the senior officers scoffed at the request. Diplomats in Baghdad also passed along intelligence of an attack, only to be told that Iraqi Special Forces were in Mosul and could handle any scenario.

On June 4, federal police in Mosul under Gharawi's command cornered Islamic State's military leader in Iraq, who blew himself up rather than surrendering. Gharawi hoped the death might avert an attack. He was wrong.

At 2:30 a.m. on June 6, Gharawi and his men returned to their operations room after an inspection of checkpoints in the city of two million. At that moment, convoys of pickup trucks were advancing from the west, driving across the desert that straddles Iraq's border with Syria. Each vehicle held up to four IS fighters. The convoys shot their way through the two-man checkpoints into the city.

By 3:30 a.m., the militants were fighting inside Mosul. Within three days the Iraqi army would abandon the country's second-biggest city to its attackers. The loss triggered a series of events that continues to reshape Iraq months later.

It unleashed a two-day charge by IS to within 95 miles (153 km) of Baghdad that caused the collapse of four Iraqi divisions and the capture or deaths of thousands of soldiers. It helped drive Maliki from office. And it pushed Western powers and Gulf Arab nations into launching air strikes on the Islamist militants in both Iraq and Syria.

But how Mosul was lost, and who gave the order to abandon the fight, have, until now, been unclear. There has been no official version: only soldiers' stories of mass desertions and claims by infantry troops that they followed orders to flee.

Story continues

In June, Maliki accused unnamed regional countries, commanders and rival politicians of plotting the fall of Mosul, but has since remained quiet.

Nevertheless, Baghdad has pinned the blame on Gharawi. In late August, he was charged by the defense ministry with dereliction of duty. He is now awaiting the findings of an investigative panel and then a military trial. If found guilty, he could be sentenced to death. (Four federal police officers who served under Gharawi are also in custody awaiting trial, and could not be reached.) Parliament also plans to hold hearings into the loss of Mosul.

An investigation by Reuters shows that higher-level military officials and Maliki himself share at least some of the blame. Several of Iraq's senior-most commanders and officials have detailed for the first time how troop shortages and infighting among top officers and Iraqi political leaders played into Islamic State's hands and fueled panic that led to the city's abandonment. Maliki and his defense minister made an early critical mistake, they say, by turning down repeated offers of help from the Kurdish fighting force known as the peshmerga.

Gharawi's role in the debacle is a matter of debate. A member of the country's dominant Shi'ite sect, he alienated Mosul's Sunni majority before the battle, according to the provincial governor and many citizens. That helped give rise to IS sleeper cells inside Mosul. One Iraqi officer under his command faulted Gharawi for not rallying the troops for a final stand.

For his part, Gharawi says he stood firm, and did not give the final order to abandon the city. Others involved in the battle endorse that claim and say Gharawi fought until the city was overrun. It was only then that he fled.

Gharawi says three people could have given the final order: Aboud Qanbar, at the time the defense ministry's deputy chief of staff; Ali Ghaidan, then commander of the ground forces; or Maliki himself, who personally directed his most senior officers from Baghdad. The secret of who decided to abandon Mosul, Gharawi says, lies with these three men. Gharawi says a decision by Ghaidan and Qanbar to leave Mosul's western bank sparked mass desertions as soldiers assumed their commanders had fled. A senior Iraqi military official backs that assertion.

None of the three men have commented publicly on their decisions in Mosul. Maliki has declined Reuters requests for an interview for this article. Qanbar has not responded, while Ghaidan could not be reached.

Lieutenant General Qassim Atta, a military spokesman with close ties to Maliki, told Reuters last week that Gharawi "above all others ... failed in his role as commander." The rest, he said, "will be revealed before the judiciary."

In many ways, Gharawi's story is a window into Iraq. The Shi'ite general has been a key figure since 2003, when the Shi'ites began gaining power after the United States toppled Saddam Hussein and his Sunni-dominated Baath Party. Shi'ite leaders once saluted Gharawi as a hero, while Sunnis see him as a murderer who used Iraq's war on extremism as a cover for extorting money from businesses and menacing innocent people with arrests and killings.

Gharawi rose through a military riven by sectarian splits, corruption and politics. He is now trapped by those same forces. The decision to punish him and ignore the role of higher-level figures shows not just that rebuilding the military will be difficult, but also why the country risks breakup. As Mosul proved, the Iraqi army is a failed institution at the heart of a failing state.

Gharawi, in his own telling, has become a scapegoat, a victim of the deal-making and alliances that keep Iraq's political and military elite in place. Ghaidan and Qanbar, longtime confidantes of Maliki, have been dispatched to a pensioned retirement. Gharawi, who is living in his home town in the south of Iraq, says his bosses are pinning the faults of a broken system on him.

"They want just to save themselves from these accusations," he told Reuters during a visit to Baghdad two weeks ago. "The investigation should include the highest commanders and leadership ... Everyone should say what they have, so the people know."

ROAD TO MOSUL

Gharawi expected Mosul to be hell. In the years after the U.S.-led invasion of Iraq, the city had become an epicenter for the al Qaeda and Sunni insurgency. Former Baathists and military commanders lived in the province of Nineveh. The Kurds also had a foothold in the city; after Saddam's fall they came to dominate the security forces and local government.

In 2008, two years after he became prime minister, Maliki began to assert his power there. Seeing the Kurds as potentially disloyal, he began to purge Kurdish officers from Mosul's two army divisions and insert his own men to protect Baghdad's interests. He appointed a string of commanders who antagonised local Kurds and Sunnis. In 2011, he tapped Gharawi.

The general was already a survivor of Iraq's political system. Despite the fact he was a Shi'ite, he had been a member of Saddam's Republican Guard. In 2004, after Saddam's fall, Washington had backed Gharawi to lead one of Iraq's new National Police Divisions.

It was a brutal period. The Shi'ite-dominated security forces – including the police – were connected to a spate of extrajudicial killings. The Americans accused Gharawi of running his police brigades as a front for Shi'ite militias blamed for the murder of hundreds of people, mostly Sunnis. U.S. and Iraqi officials investigated Gharawi for his command of Site Four, a notorious Baghdad jail where prisoners were allegedly tortured or sold to one of the biggest and most brutal Shi'ite militias.

In late 2006, U.S. officials moved to stop the killings, pressuring Maliki to dismiss Gharawi and try him for torture. Maliki reassigned Gharawi but would not try him. U.S. Ambassador Ryan Crocker recalled a near shouting match with Maliki over the general. "One of my many disappointments was not getting that sorry-assed failure," Crocker said in 2010.

Gharawi says he did nothing wrong during that period and has nothing to apologize for. It was civil war, he said. The Sunni insurgency was bent on demolishing the Shi'ite-led government. Gharawi's brother was killed by Sunni militants. "We worked under special circumstances. We prevented civil war. We actually stopped it. Where are our mistakes?"

LEOPARD SKIN AND A WARNING

After his demotion, Gharawi bided his time, a gloomy figure in his dim-lit Green Zone villa, decorated with old photos, including a few of him with U.S. senators and Donald Rumsfeld. He was given a series of minor jobs. Maliki's office regularly proposed him for higher positions only to be blocked by U.S. officials. As the U.S. military prepared to leave Iraq, Maliki appointed Gharawi the top federal police commander in Mosul.

There, Gharawi recaptured his glory. State television showed him standing on Nineveh's sweeping plains in blue camouflage as he announced a successful operation against a terror plot. Maliki rewarded him with property in an affluent Baghdad neighborhood.

In his house in the capital on a short leave from Mosul last December, Gharawi sat proudly on a leafy green couch, surrounded by cream-coloured walls, a faux leopard skin rug, and shiny tiled floors. An oil portrait of himself hung on the wall. He bragged about arrests and flipped through pictures of jihadists his men had captured.

Despite his triumphs, he was frank about the insurgency that re-emerged last year as Sunnis grew frustrated with Maliki's sectarian rule. The war was at best a stalemate, Gharawi said. Al Qaeda – the Islamic State's parent organization at the time, before it split this year – was gaining ground. "I have to confess, al Qaeda is stronger than they have ever been. Qaeda needs Mosul. They think of Mosul as their emirate," he said.

Gharawi said he lacked the troops to secure the province. He also faced growing opposition from Sunnis in Mosul, who accused him and his men of extra-judicial killings, allegations Gharawi rejected.

In March, Maliki appointed him Nineveh's operational commander. Security in Iraq was deteriorating. In Anbar province, to Nineveh's southwest, violence had drawn in three military divisions against IS militants and angry Sunni tribes. The government had lost control of the highways from Baghdad to the north. IS militants regularly set up fake checkpoints and ambushed vehicles.

THE FALL

As IS fighters raced towards Mosul before dawn on June 6, the jihadists hoped only to take a neighborhood for several hours, one of them later told a friend in Baghdad. They did not expect state control to crumble. They hurtled into five districts in their hundreds, and would, over the next few days, reach over 2,000 fighters, welcomed by the city's angry Sunni residents.

The first line of Mosul's defense was the sixth brigade of the Third Iraqi army division. On paper, the brigade had 2,500 men. The reality was closer to 500. The brigade was also short of weapons and ammunition, according to one non-commissioned officer. Infantry, armor and tanks had been shifted to Anbar, where more than 6,000 soldiers had been killed and another 12,000 had deserted. It left Mosul with virtually no tanks and a shortage of artillery, according to Gharawi.

There was also a problem with ghost soldiers – men on the books who paid their officers half their salaries and in return did not show up for duty. Investigators from the defense ministry had sent a report on the phenomenon to superiors in 2013. Nothing was heard back, a sergeant who was based in Mosul told Reuters.

In all, there were supposed to be close to 25,000 soldiers and police in the city; the reality, several local officials and security officers say, was at best 10,000. In the district of Musherfa, one of the city's main entry points, there were just 40 soldiers on duty the night of June 6.

As the militants infiltrated the city, they seized military vehicles and weapons. The sergeant based there said they also hanged soldiers and lit them ablaze, crucified them, and torched them on the hoods of Humvees.

On the western edge of Tamoz 17 neighborhood, police from the fourth battalion saw two Humvees and 15 pickup trucks approach, spraying machine gun fire.

"In my entire battalion we have one machine gun. In each pickup they had one," said head of the battalion, Colonel Dhiyab Ahmed al-Assi al-Obeidi.

Gharawi ordered his forces to form a defensive line to cordon off the besieged western Mosul neighbourhoods from the Tigris River. Gharawi said he received a call from Maliki to hold things until the arrival of Qanbar, the deputy chief of staff at the defense ministry, and Ghaidan, who commanded Iraqi ground forces.

Qanbar is a member of Maliki's tribe, while Ghaidan had long assisted Maliki in security operations, according to senior officers and Iraqi officials. The two men outranked Gharawi and automatically took formal charge of the Mosul command on June 7.

On the morning of June 8, Gharawi met Nineveh governor Atheel Nujaifi. The governor was no friend – he had previously accused Gharawi of corruption, an allegation the general rejected.

Now the city's fate hinged on Gharawi. One of Nujaifi's advisers asked the general why he had not counter-attacked.

"There are not enough forces," Gharawi told them.

General Babakir Zebari was Gharawi's superior and chief of staff for Iraq's armed forces back in Baghdad. He agrees there were not enough men to defeat the jihadists. And Maliki had already rejected a chance to change that.

On June 7, Kurdistan President Massoud Barzani had offered to send Kurdish peshmerga fighters to help. The offer went all the way up to Maliki, who rejected it twice through his defense minister, according to Zebari.

United Nations and U.S. diplomats also attempted to broker an arrangement acceptable to Maliki, who remained suspicious of the Kurds' intent. Maliki insisted there were more than enough Iraqi forces. Barzani's office confirmed Kurdish offers of help were rejected.

On the afternoon of June 8, the Islamic State surged. More than 100 vehicles, carrying at least 400 men, had crossed to Mosul from Syria since the start of the battle. Sleeper cells hiding in the city had been activated and neighbourhoods rallied to them, according to police and military.

The insurgents bombed a police station in the al-Uraybi neighborhood and charged into the area around the Mosul Hotel, an abandoned building on the western bank of the Tigris transformed into a battle post for 30 men from SWAT, an emergency police unit.

Gharawi and his federal police pounded Islamic State-controlled areas with artillery.

For a moment, "the morale of Mosul got higher," Gharawi said.

Within hours, though, Gharawi's command was thrown into disarray. Multiple military sources say Ghaidan and Qanbar sacked a divisional commander after he refused to send men to defend the Mosul Hotel. The sacked general, who reported to Gharawi, theoretically commanded 6,000 men, though many were AWOL.

General Zebari calls the order another huge mistake: "In crisis, you can't replace the commander."

TURNING POINT

By June 9, the fourth battalion's Colonel Obeidi and 40 of his men were among the very last local police fighting to hold back the jihadists in western Mosul. The rest had either joined the jihadists or run away.

Just before 4:30 p.m., a military water tanker raced towards the Mosul Hotel where Obeidi and his men were stationed. The police fired at the tanker, which detonated, setting off a massive fireball and hurtling shrapnel. "I didn't feel anything," said Obeidi, whose leg was ripped open by the blast. "The sound shook the whole of Mosul but I didn't hear a thing."

Clutching his handgun, Obeidi vowed to fight on. Police carried him to a boat to cross the Tigris to safety. Military officers, local officials, and even U.S. officials later testifying to Congress said the hotel attack was what broke the army and police in Mosul. After that, the defensive line in the west of the city melted away.

Barely three hours later, as reports spread of federal police burning their camps and discarding their uniforms, the Nineveh governor and his adviser met with Qanbar and Ghaidan in the Operation Command near the airport.

The adviser, Khaled al-Obeidi, was himself a retired general and a newly elected lawmaker. (He is unrelated to police Colonel Obeidi). He urged the commanders to go on the offensive with the Second Division, which sat relatively untouched across the river in eastern Mosul.

Qanbar said that they had a plan. Nujaifi's adviser then urged Gharawi to attack. Gharawi said he could not risk moving the soldiers and federal police he had left.

"We can get you the force," the adviser said.

Qanbar interrupted. The governor and adviser should do their work, he said. "We will do ours."

The governor and his adviser left the base at 8:25 p.m., unsure of what the military's plan was.

Shortly before 9:30 p.m., Qanbar and Ghaidan told Gharawi they were withdrawing across the river.

"They said goodbye and that's it. They didn't give me any information or any reason," Gharawi said.

They stripped Gharawi of 46 men and 14 pickup trucks and Humvees – the bulk of his security detail – say Gharawi and other officers. The two senior generals moved the city's command to a base on the city's eastern edge, according to multiple accounts.

Ghaidan and Qanbar's retreating convoy created the impression that Iraq's security forces were deserting, Gharawi said. "This is the straw that broke the camel's back. This was the biggest mistake."

Soldiers assumed their leaders had fled and within a couple of hours most of the Second Division had deserted the city's east, Nujaifi, the governor, told Reuters.

Gharawi and 26 of his men stayed hidden in their operations base in the west, which swarmed with insurgents. That night, Gharawi said, Ghaidan phoned him and assured him the army was holding eastern Mosul.

Ghaidan and Qanbar both left Mosul overnight, arriving in Kurdistan on June 10, according to Zebari, the chief of staff back in Baghdad.

"Of course once the commander leaves the soldier behind, why would you want to fight?" asked Zebari. "The senior commander is the brains of operation. Once he runs, the whole body is paralysed."

Zebari says he doesn't know who gave the order to leave. Qanbar and Ghaidan were bypassing the defense ministry and reporting directly to Maliki, Zebari told Reuters.

Early the next morning, Zebari rang Gharawi and urged him to leave the operation command center. "You are going to get killed. Please withdraw," both men remember Zebari saying.

Gharawi refused and insisted he needed approval from Maliki's military office to leave.

Soon after, Gharawi decided to fight his way across a bridge to eastern Mosul. He rang Ghaidan to tell him. "I am going to be killed. I am surrounded by all directions. Send the prime minister my greetings. Tell the prime minister I have done everything possible that I can do."

He and his men crammed into five vehicles and headed across the river. On the east bank, their five vehicles were set ablaze. They dodged bullets and stones. Three of the men were shot dead. It was every man for himself, Gharawi said.

In the east, Gharawi and three of his men commandeered an armoured vehicle with flat tires and headed north to safety.

AFTERMATH

By August, Gharawi was back in his ancestral home in southern Iraq, looking after his children, unsure what to do next. One day he received a call from a friend in the defense ministry: He was under investigation for dereliction of duty in Mosul.

At the same time, Maliki promoted Qanbar and moved to protect Ghaidan. After the prime minister resigned on Aug. 15, though, the two men were also forced into retirement.

It marked an effort by Haider al-Abadi, the new prime minister, to start to clean and rebuild the Iraqi forces. Abadi has closed the office Maliki used to direct commanders and has quietly retired officers seen as loyal to his predecessor. Purging the security institutions of their sectarianism, money-making schemes and political manoeuvrings will take years.

And for now, Gharawi must take the blame for Mosul. Zebari believes that's unfair. "Gharawi was an officer doing a job, but his luck ran out just like many other officers," he said. "All of us have to shoulder some of the responsibility. Every one of us."

Two weeks ago in Baghdad, face unshaven, voice hoarse, Gharawi indicated a begrudging acceptance of his fate, whatever it might be.

"Maybe I'll be pardoned, maybe I'll be imprisoned, maybe I'll be hanged," he said.

(Parker reported from Baghdad and Arbil, Salman from Baghdad, and Coles from Arbil; With additional reporting by Ahmed Rasheed and Saif Hameed in Baghdad; Edited by Simon Robinson)