The alleged Somali mastermind of the assault on a posh mall that killed scores and jolted Kenya is a man of contradictions.

Ahmed Godane is bookish, eloquent in both Arabic and Somali, recites poetry and is known to quote from obscure academic journals, analysts say. Yet he trained and fought in Afghanistan for the jihadist cause and has ruthlessly killed most of his rivals to seize control of al-Shabab, a Somali militia linked to al-Qaida that has asserted responsibility for the Westgate Mall attack.

Al-Shabab has said the assault, which began Saturday, was revenge for Kenya sending troops into Somalia. But the carnage had just as much to do with the struggles inside the militia and Godane's desire to make al-Shabab — and himself — stronger and more relevant in the global jihad against the United States and its allies, according to analysts.