By the time the United States withdrew from its long, bloody encounter with Iraq in 2010, it thought it had declawed a once fearsome enemy: the Islamic State of Iraq and Syria, which had many names and incarnations but at the time was neither fearsome nor a state.

Beaten back by the American troop surge and Sunni tribal fighters, it was considered such a diminished threat that the bounty the United States put on one of its leaders had dropped from $5 million to $100,000. The group's new chief was just 38 years old, a nearsighted cleric, not even a fighter, with little of the muscle of his predecessor, Abu Musab al-Zarqawi — the godfather of Iraq's insurgency, killed by the American military four years earlier after a relentless hunt.

"Where is the Islamic State of Iraq you are talking about?" the Yemeni wife of one leader demanded, according to Iraqi police testimony. "We're living in the desert!"

Yet now, five years later, ISIS is on a very different trajectory. It has wiped clean a 100-year-old colonial border in the Middle East, controlling millions of people in Iraq and Syria. It has overcome its former partner and eventual rival, al Qaeda, first in battle, then as the world's pre-eminent jihadist group in reach and recruitment.

It traces its origins both to the terrorist training grounds of Osama bin Laden's Afghanistan and to America's invasion of Iraq in 2003, and it achieved its resurgence through two single-minded means: control of territory and, by design, unspeakable cruelty.

Its emblems are the black flag and the severed head.

Since last spring the group, also known as the Islamic State or ISIL, has been expanding beyond its local struggle to international terrorism. In the past few weeks, it did that in a spectacular way, first claiming responsibility for downing a Russian planeload of 224 people, then sending squads of killers who ended the lives of 43 people in Beirut and 130 in Paris.

As the world scrambles to respond, the questions pile up like the dead: Who are they? What do they want? Were signals missed that could have stopped ISIS before it became so deadly?

And there were, in fact, more than hints of the group's plans and potential. A 2012 report by the United States Defense Intelligence Agency was direct: The growing chaos in Syria's civil war was giving Islamic militants there and in Iraq the space to spread and flourish. The group, it said, could "declare an Islamic state through its union with other terrorist organizations in Iraq and Syria."

"This particular report was one nobody wanted to see," said Lt. Gen. Michael T. Flynn, who ran the defense agency at the time. "It was disregarded by the White House," he said. "It was disregarded by other elements in the intelligence community as a one-off report. Frankly, at the White House, it didn't meet the narrative."

"There was a strong belief that brutal insurgencies fail," said William McCants of the Brookings Institution and a leading expert on ISIS, explaining the seeming indifference of American officials to the group's rise. "The concept was that if you just leave ISIS alone, it would destroy itself, and so you didn't need to do much."

There is no evidence that the two central figures in ISIS's ascendance ever met, but a faith in brutality — as a strategy unto itself — was a shared belief. Both were based in Iraq, seemingly a key to top leadership in ISIS. Otherwise, they could not be more different.

The first, Zarqawi, a onetime thief, was a tattooed Jordanian and a reformed drinker of extreme personal violence whose own mother had proclaimed him not very smart. The full details of the second, an Iraqi now known as Abu Bakr al-Baghdadi, the group's current and reclusive leader, are incomplete, but he is known more as a quiet Sunni cleric, likely with an advanced degree in Islamic studies, whose tribe traces its lineage to the Prophet Muhammad himself. He likes soccer.

Each was shaped by the larger forces of the Islamic world, in particular religious zeal, al Qaeda, and America's war with Iraq. Each rejected the secular culture of the West, which many say was the target of the attacks in Paris.

As difficult as it might be for Americans to believe after the Sept. 11 terrorist attacks and more than a decade of thinking of bin Laden as the basest terrorist planner, Zarqawi was perhaps more violent and more apocalyptic in his outlook than the al Qaeda leader. He grew up poor in the industrial Jordanian city of Zarqa, in a two-story concrete house, with seven sisters and two brothers.

His youth was spent as a petty criminal, but after adopting a strict form of Islam, he turned to jihad and traveled to Pakistan and Afghanistan, where he actually met with bin Laden. Al Qaeda, though, was hesitant about letting him join — an early sign of a rivalry that would fester into a final split years later.

While he had a reputation as a thug, Zarqawi demonstrated keen instincts for strategic thinking. He clearly saw that the United States would invade Iraq, slipping into the country in 2003, and by some accounts setting up sleeper cells to attack the invaders. Later, he took full advantage of America's marginalization of Saddam Hussein's ruthless Baathist soldiers and bureaucracy.

Stoking both attacks against American soldiers and tensions with Shiites, he built an insurgency responsible for keystone moments of the early war: assaults on the United Nations headquarters in Baghdad, the Shiite Imam Ali Mosque, and other targets large and small.

The United States raised the bounty on him to $25 million, equal to that for bin Laden. But the videoed decapitations and wanton sectarian killings of Muslim civilians — along with his desire to proclaim an Islamic state — also provoked an unusual rebuke in 2005 from bin Laden's No. 2, Ayman al-Zawahri (now the top leader of al Qaeda).

Beheadings, Zawahri wrote, may stir the passions of "zealous young men" but ordinary Muslims "will never find them palatable."

An American airstrike finally killed Zarqawi in June 2006. Four months later, his successors declared the founding of the Islamic State of Iraq. It was one of scores of Sunni groups fighting mostly in northern Iraq, and accounts differ as to how effective or distinct it was. Still, Rod Coffey, in March 2008 an American lieutenant colonel, recalls vividly finding ISIS's black, gold-fringed banner some 50 miles north of Baghdad.

"These were people who, unlike bin Laden, said, 'We are going to control ground now, create a government, create a society, run this place as a steppingstone to creating a caliphate,'" Coffey, now 54 and retired, said. Near the flag, he found a mass grave of 30 bodies, executed.

McCants, the Brookings scholar, has done deep research into the origins of Baghdadi, the current leader of ISIS, but much remains unclear. In his book The ISIS Apocalypse, McCants traces the rise of a lower-middle class man born in 1971 in the hard-line Sunni city of Samarra, Iraq. Baghdadi's family ties to Saddam Hussein's army were strong. His own bad eyesight would keep him from active duty.

Apart from his piety, one fact is not in dispute: Baghdadi is a former inmate of Camp Bucca, the American prison in southern Iraq now widely agreed to have been crucial in the formation of Iraqi jihadists, housed in proximity behind blast walls and spools of razor wire. It earned names like "the Academy" or the "Jihadi University," where the United States would unintentionally create the conditions ripe for training a new generation of insurgents.

In ISIS: Inside the Army of Terror, authors Michael Weiss and Hassan Hassan quote Maj. Gen. Douglas Stone, a prison commander in Iraq: "If you were looking to build an army, prison is the perfect place to do it. We gave them health care, dental, fed them, and most importantly, we kept them from being killed in combat."

Looking back this month, John Brennan, the CIA director, recounted in a speech to a Washington think tank that ISIS was "pretty much decimated when U.S. forces were there in Iraq." The group "had maybe 700 or so adherents left," Brennan said. "And then it grew quite a bit."

Americans wanted to believe that the Iraq war had ended in triumph, and the troops were soon withdrawn. But almost immediately tensions began rising between the Sunnis and the Shiite-dominated government of Prime Minister Nuri al-Maliki — supported by the United States and Iran, the Shiite giant to the east. Salaries and jobs promised to cooperating tribes were not paid. There seemed little room for Sunnis in the new Iraq. The old Sunni insurgents began to look appealing again.

Baghdadi was named head of ISIS in 2010, and his group seemed particularly adept at exploiting Sunni fears. McCants recounts how they entered a period of concentrated "reflection," developing a detailed, militarily precise plan for resurrection in 2009.

The document, parts of which are translated in McCants' book, is strikingly self-critical, acknowledging that ISIS had lost some of its aggressiveness and did not control territory. It advised adopting the American tactic of co-opting the Sunni tribes, conceding that the U.S.'s recruiting "the tribes to eliminate the mujahedeen was a clever, bold idea."

The document also makes clear the need for a media strategy — a recommendation the group went on to follow with great success, exploiting social media to spread its message and to attract recruits, many in the more technologically savvy West. Then a civil war broke out in Syria — a new and promising front for ISIS's ambitions.

Early on, ISIS's rivals underestimated it, only to face deadly attacks from the group later. They were not the only ones — Obama likened the group to the "J.V. team." And ISIS fighters often did seem like buffoons, especially the foreign ones, who came from across the Middle East, Central Asia, and Europe. Many could not speak Arabic. And some barely knew anything of Islamic theology. They posted on social media pictures of themselves mugging for the camera as they swam in the Euphrates River, or complaining that it was difficult to find Nutella in the shops.

But some were serious, determined, and ideologically motivated. "I have chosen the state," one man who identified himself as a Saudi fighter said in an online interview, explaining that his interest was less in overthrowing Syrian President Bashar al-Assad than in striving for a caliphate, "because I support its method of unification and implementation of the sharia of God."

ISIS did, in fact, succeed in building the semblance of a state, providing services as well as imposing the harshest of rules. It worked to self-finance, through oil, trade in priceless antiquities, and, many say, simple criminal enterprises like kidnapping and extortion.

And, as it had always promised, ISIS was brutal, frightening fellow groups and the wider world with practices like sexual slavery, immolations, crucifixions, and beheadings. Those included killings of the journalist James Foley and others in well-produced videos that spread through social media, ending often with a shot of a bloody severed head.

The climax of ISIS's rise came in June 2014, when it captured Mosul, Iraq's second-largest city, erasing the century-old border between Iraq and Syria established after World War I. The caliphate had been declared the month before, but soon after Mosul's capture, Baghdadi, in a black SUV, arrived at the Nuri Mosque in Mosul in a rare appearance to make that state formal.

There was another victory, which had played out behind the scenes in bitter missives between al Qaeda central, ISIS, and its Qaeda-sponsored affiliate, the Nusra Front. Baghdadi rejected demands from Zawahri, leader of al Qaeda after bin Laden's death, that he step in line under his rule. No, Baghdadi said: ISIS was supreme and separate. Al Qaeda central had become, in some sense, the cautious, increasingly irrelevant uncle. Paris was the proof of that.

Excerpted from an article that originally appeared in The New York Times. Reprinted with permission.