But al-Shabab’s top leadership has resisted the Islamic State at every turn, launching a series of attacks on the factions that defected and arresting and executing alleged Islamic State sympathizers.