IRBIL, Iraq -- 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 U.S. officials by surprise. But the gains actually were 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 U.S. officials judged as they were winding down the U.S. 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 U.S. 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, Mr. 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. Mr. 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," Mr. Fishman said. "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 theater 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 U.S. officials.
That is partly because its prospects initially appeared limited at the end of the U.S. 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 U.S. 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," Mr. Fishman said.
The group gained strength in Syria through a two-pronged approach of launching strategic attacks to seize resources such as 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.
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 favor of arming Syrian rebels, said last week at an event in New York City 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."
The group's rise is directly connected to the U.S. legacy in Iraq. The U.S. 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, Mr. Baghdadi, who is believed to have earned a doctorate in Islamic studies from a university in Baghdad, relocated to Syria, according to the U.S. 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.