NAIROBI, Kenya — The terror group Al Shabab, suspected in the weekend attack that killed 79 people in the Somali capital, Mogadishu, has proved resilient in recent years even as it lost territory, suffered high-level defections and faced increasing airstrikes by the United States.

Almost a decade since African peacekeeping forces kicked the Al Qaeda-linked group out of Mogadishu, it has become deft in handling its operations, versatile in using guerrilla tactics and prolific in manufacturing bombs. Over the past few years, the Shabab killed hundreds of people in attacks at home and on neighboring Kenya, assaulted an American military base outside Mogadishu and overran military bases of the African Union peacekeeping mission in Somalia.

To finance itself, the militants have set up an extensive racketeering system that levies fees on sales of agricultural produce in southern and central Somalia — areas that are the stronghold of the group. They also tax imports into the Mogadishu port, according to the United Nations.

The Shabab have also been able to infiltrate federal institutions — they claimed to have recruited a government employee to kill Mogadishu’s mayor, Abdirahman Omar Osman, in July. And the group’s growing assertiveness was in evidence when it declared war last year on pro-Islamic State groups in Somalia in a fight over territory.