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 Syria (ISIS) to issue edicts laying out the 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 were the realization of a yearslong strategy of state-building that the group 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 Syria.

Now that President 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, issuing annual reports, to document its progress in achieving its goals.

Religion paramount

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 pragmatic in forming alliances and gaining and ceding territory. In discussing its strategy, Fishman described the 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 and 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.

Under this vision, religion is paramount. Referring to citizens under the group’s 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 it has done consistently: free Sunnis from prison.

“When you go back and read it, it’s all there,” said Fishman.

More recent annual reports, including one released in late March that 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 the Levant — is “functioning as a military rather than as a terrorist network.”

Opportunity in Syria

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. In the middle of 2012, as the group strengthened and United Nations data showed civilian casualties in Iraq on the rise, Antony 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 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.

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 “invaded Syria from Mosul long before it invaded Mosul from Syria,” Fishman said.

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 past six months.

In congressional testimony in February, a top army intelligence official, Lt. Gen. Michael 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 favor of arming Syrian rebels, said last week in New York hosted by the Council on Foreign Relations: “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 U.S. counterterrorism official said Friday: “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 was formally ejected from al-Qaida this year after that organization’s leader, Ayman al-Zawahiri, 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 competition for resources and standing in the wider international jihadist community.

Chilling propaganda

Perhaps the best indication of how the group sees itself these days is a recent promotional video, “The Rattling of the Sabers.”

The hourlong video is a slickly produced, hyperviolent propaganda piece that idolizes the group’s fighters as they work for their main goals: founding an Islamic state and slaughtering enemies, mostly the Iraqi security forces and Shiites.

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.