Abu Mansoor Mukhtar Robow, an elusive, charismatic militant who was once a senior commander of the Shabab in Somalia, surrendered to government forces on Sunday in a surprise move that could weaken the country’s Islamist militants.

More than any deep change of heart, Mr. Robow may have turned himself in simply to save his skin. According to Somali security officials, hard-line elements within the Shabab — in which Mr. Robow had been a stalwart before falling out in 2013 with its leader at the time — had turned against him, wiping out many of his soldiers.

For the past several months, Mr. Robow — who once had an American bounty on his head — had essentially been on the run from his own group, setting up a base in Abal Village, in southwest Somalia. In the last few days, government officials had been trying to help him and his forces escape.

“We contacted him many times, and we understood each other,” said Moalim Ahmed, the mayor of Hudur, a small town in the area where Mr. Robow operated.