When Islamic militants rampaged through the Iraqi city of Mosul last week, robbing banks of hundreds of millions of dollars, opening the gates of prisons and burning army vehicles, some residents greeted them as if they were liberators and threw rocks at retreating Iraqi soldiers.
It took only two days, though, for the fighters of the Islamic State of Iraq and the Levant to issue edicts laying out the harsh terms of Islamic law under which they would govern, and singling out some police officers and government workers for summary execution.
With just a few thousand fighters, the group's lightning sweep into Mosul and farther south appeared to catch many Iraqi and US officials by surprise. But the gains were actually the realization of a yearslong strategy of state-building that the group itself promoted publicly.
"What we see in Iraq today is in many ways a culmination of what the ISI has been trying to accomplish since its founding in 2006," said Brian Fishman, a counterterrorism researcher at the New America Foundation, referring to the Islamic State in Iraq, the predecessor of the Islamic State of Iraq and the Levant.
Now that President Barack Obama is weighing airstrikes and other military aid to block the militants' advance in Iraq, an examination of its history through its own documents indicates that the group has been far more ambitious and effective than US officials judged as they were winding down the US involvement in the war.
The Sunni extremist group, while renowned for the mayhem it has inflicted, has set clear goals for carving out and governing a caliphate, an Islamic religious state that spans Sunni-dominated sections of Iraq and Syria. It has published voluminously, even issuing annual reports, to document its progress in achieving its goals.
Under the leadership of Abu Bakr al-Baghdadi, who once spent time in a US detention facility, the group has shown itself to be unrelentingly violent and purist in pursuing its religious objectives, but coldly pragmatic in forming alliances and gaining and ceding territory. In discussing its strategy, Fishman described the militant group as "a governmental amoeba, constantly shifting its zone of control across Iraq's western expanses" as its forces redeploy.
In 2007 the group published a pamphlet laying out its vision for Iraq. It cited trends in globalization as well as the Quran in challenging modern notions of statehood as having absolute control over territory. Fishman referred to the document as the "Federalist Papers" for what is now the Islamic State of Iraq and the Levant.
Under this vision, religion is paramount over administering services. Referring to citizens under its control, the pamphlet states, "improving their conditions is less important than the condition of their religion." And one of the most important duties of the group, according to the pamphlet, is something that it has done consistently: free Sunnis from prison.
"When you go back and read it, it's all there," said Fishman. "They are finally getting their act together."
More recent annual reports, including one that was released at the end of March and ran more than 400 pages, list in granular detail the group's successes, through suicide attacks, car bombs and assassinations, on the battlefield.
The group's recent annual report, wrote Alex Bilger, an analyst at the Institute for the Study of War, makes clear that "the ISIS military command in Iraq has exercised command and control over a national theatre since at least early 2012," and that the group — which is also known as the Islamic State of Iraq and Syria — is "functioning as a military rather than as a terrorist network."
Although the group got its start battling the Americans in Iraq, its success after the occupation ended was largely missed — or played down — by US officials. In the middle of 2012, as the group strengthened and UN data showed civilian casualties in Iraq on the rise, Antony J Blinken, the national security adviser to Vice-President Joe Biden, wrote that violence in Iraq was "at historic lows."
That is partly because its prospects initially appeared limited at the end of the US occupation. During the sectarian war that began in 2006, Sunni jihadists antagonized the public with their brutality and attempts to impose Islamic law, and suffered defeats at the hands of tribal fighters who joined the US counterinsurgency campaign, forcing them to retreat from western Iraq to areas around Mosul.
But with the outbreak of civil war across the border in Syria three years ago, the group saw new opportunities for growth. The Islamic State of Iraq and the Levant "invaded Syria from Mosul long before it invaded Mosul from Syria," Fishman said.
The group gained strength in Syria through a two-pronged approach of launching strategic attacks to seize resources like arms caches, oil wells and granaries, while avoiding protracted battles with government forces that have ground down Syria's other rebels. In Iraq, government resistance crumbled in many areas it has seized.
As stunning as the move on Mosul was, the group had been solidifying its control of Raqqa, in Syria, for more than a year, and of Fallujah, in western Iraq, for the last six months.
In congressional testimony in February, a top army intelligence official, Lt Gen Michael T Flynn, said the group, "probably will attempt to take territory in Iraq and Syria to exhibit its strength in 2014."
Now that the spotlight has shifted to Iraq, the decision by the Obama administration not to arm moderate Syrian rebels at the outset is coming under scrutiny by critics who say the hands-off policy allowed the extremists to flourish.
Former secretary of state Hillary Rodham Clinton, who argued in favour of arming Syrian rebels, said last week at an event in New York hosted by the Council on Foreign Relations, "this is not just a Syrian problem anymore. I never thought it was just a Syrian problem. I thought it was a regional problem. I could not have predicted, however, the extent to which ISIS could be effective in seizing cities in Iraq and trying to erase boundaries to create an Islamic state."
A US counterterrorism official said Friday that "the group appears to be benefiting from a regional strategy that looks at Syria and Iraq as one interchangeable battlefield, allowing it to shift resources and manpower in pursuit of military objectives."
The group's rise is directly connected to the US legacy in Iraq. The US prisons were fertile recruiting grounds for jihadist leaders, and virtual universities, where leaders would indoctrinate their recruits with hard-line ideologies. The group's leader, al-Baghdadi, who is believed to have earned a doctorate in Islamic studies from a university in Baghdad, relocated to Syria, according to the US government, which has offered a $10 million reward for information leading to his capture.
The group was formally rejected from al-Qaida earlier this year after that organization's leader, Ayman al-Zawahri, ordered it to withdraw to Iraq and leave operations in Syria to the local al-Qaida affiliate, the Nusra Front. The split led to a bitter rivalry between the two groups, with the Islamic State of Iraq and the Levant competing with al-Qaida for resources and standing in the wider international jihadist community.
Perhaps the best indication of how the group sees itself these days is a recent promotional video called "The Rattling of the Sabers".
The hourlong video is a slickly produced, hyper-violent propaganda piece that idolizes the group's fighters as they work for two of their main goals: founding an Islamic state and slaughtering their enemies, mostly the Iraqi security forces and Shias.
Some scenes show bearded, armed fighters from around the Arab world renouncing their home countries and shredding their passports. Other scenes show them preaching at mosques and soliciting pledges of allegiance to al-Baghdadi. Still other scenes emphasize attacks. Its fighters carry out drive-by shootings against men they accuse of being in the Iraqi army, in some cases chasing them through fields before grabbing and executing them.
The group has calibrated different strategies for Syria and Iraq. In Syria, it has mainly focused on seizing territory that has already fallen out of government hands, but had been poorly controlled by other rebel groups. In Iraq, though, it has exploited widespread disenchantment among the country's Sunnis with the government of Prime Minister Nouri al-Maliki, to align with other Sunni militant groups, such as one organization that is led by former officers of Saddam Hussein's Baath Party.
While many of these groups, including the Baathists and other tribal militias, seemed to have joined with the Islamic State of Iraq and the Levant because of a common enemy, its organization and resources could lure them to a more durable alliance that could make it even more difficult for Maliki's government to reassert control.
"What is very dangerous is that all these forces now have the same goal," said Hassan Abu Hanieh, a Jordanian expert on Islamist groups. Referring to the Islamic State of Iraq and the Levant by the alternate name, he said: "ISIS has been able to take advantage of widespread anger and to base their identity on fighting Shias."