Al-Qaeda’s main affiliate in Iraq avoided extinction at the hands of U.S. and Iraqi forces a decade ago by backing away from military engagements and moving the remnants of its network underground until its reemergence as the Islamic State.