MOGADISHU, Somalia — Defections from al-Qaida-linked militant group al-Shabab are accelerating as Somali and African Union troops take new territory around the capital Mogadishu, according to officials in Somalia.

Militants who abandon al-Shabab risk retaliatory assassinations from fighters still loyal to the militia but a government-run program in Mogadishu houses several hundred former fighters, many of them teenagers. The program provides them with meals, housing and courses on patriotism, anti-violence and religion.

Reliable figures on the number of defectors, however, are hard to come by. Somali government spokesman Abdirahman Omar Osman said there have been at least 500 in recent months. African Union military spokesman Lt. Col. Paddy Ankunda also said the number was rising.

Two fighters who defected from al-Shabab about four months ago and now live at the government-run program spoke to The Associated Press about their old and new lives.

Mohamed Saeed, 18, said that militants didn’t dare disclose plans about defecting with even their closest battlefield friends. Trust, he said, could get you killed. “The plan was to keep secrets to yourself,” he said.

As al-Shabab has lost its profit centers — the markets in Mogadishu the militants once taxed, for example — life on the battlefield became harder, Saeed said. Fighters often ate only one meal a day.

“Food was scarce,” he said. “Worse, mortars were raining down over us. You can’t retreat. Other armed fighters were deployed behind us to kill us if we tried to move back from the tanks shelling us.”

Al-Shabab is estimated to have several thousand fighters. It is Somalia’s most dangerous militant group, espousing an ultra-conservative brand of Islam. It has imposed harsh social rules in areas it controls, much like the Taliban did during the 1990s in Afghanistan.

Another defector, Abdiqadir Mohamed, 17, said: “I felt like I was caged like animals. We weren’t even allowed to call our parents.”

Both of the teens said they joined al-Shabab, at age 16 and 14, respectively, after being indoctrinated by their teachers, who told them they would be fighting to protect and defend Islam. The duo said they were told they would go to paradise if killed in battle but they later understood that fighting had nothing to do with religion.

Now, the former fighters sleep in large warehouses filled with beds and spend many hours hanging out under trees. Many listen to music and watch TV, with some still having jihadist songs on their mobile phones.

Hussein Arale Adan, a member of parliament, said that not all of them were to be trusted. He said one defector who joined the Somali army carried out a suicide attack against the presidential palace.

“The immediate integration of militant defectors into the army without enough rehabilitation is a wrong-headed decision,” Adan said.

Some of the fighters stay in the government program for many months. Many have trouble finding jobs because of their past associations with al-Shabab. Others stay in the program for fear they will be killed by militants in Mogadishu.

Mohamed and Saeed once fought alongside each other. They both ended up at the government-run program even though they never talked about it together. They recalled watching some of their friends killed by al-Shabab leaders.

“We only remember three of our friends killed in front of our eyes. How many were secretly killed?” Mohamed said. “You can’t wait for death every day.”

Mohamed said his al-Shabab commander complained about the increasing defections.

Only a few years ago, when al-Shabab held sway over most of Mogadishu and deadly fighting was a daily staple in Somalia’s seaside capital, the government’s military struggled to stem the flow of defections to al-Shabab. Now the flow has reversed.

Yusuf Ali, 27, who served as a field commander for al-Shabab, said many militants joined for the money.

“Joining them was a sure-fire way to get money during their first years. But now they can’t even get meals for their fighters,” Ali said. “They’ve lost their popularity. They lie about Islam. They are hated thugs because of the unjustified killings and misinterpreting religion.”

As Ali and the others spoke, a pickup truck pulled up and dropped off six new defectors with unkempt hair and muddy shoes.

“Nice to see you. After a little bit of time we are together again,” one former fighter said to the newcomers.