Today, two months after African Union (AU) troops and government forces wrested it from the hardline Islamists, the sprawling settlements of rag huts on the fringes of the capital Mogadishu are emptying, as many return to the city.
“It is much better now, as during the Shebab time we lost our freedom,” said Mohamad Barissa Hussein, a walking stick slung across his shoulders, as he helped herd 25 camels over the bridge crossing the river into Afgoye.
“They would just stop us and they would beat us and flog us for no reason,” the 55-year-old remembered, scratching his red-dyed beard.
Business is slowly growing too. Leaning on the counter of her corrugated iron shop, with the shelves stacked neatly with bottled water and juice, Katra Ibrahim points at the small crowd of people on the road in front.
“In terms of business, the situation is 100 percent much better now, even though the security is not so good,” said Ibrahim, 27, a mother of five, as women sold grapefruit on the sandy ground nearby.
“When the Shebab were here there was no movement, no one coming from Mogadishu, but now the town is much busier because people can come back.”
Until a few months ago, Afgoye and the road linking it to Mogadishu some 30 kilometres away – known as the Afgoye Corridor – was a sprawling mass of human misery.
The United Nations estimated more than 400,000 people were living in the area at the start of the year – making it the world’s largest concentration of displaced people. Many had fled extreme drought and fighting elsewhere.
While many now think that estimate to have been too high – the hardline Shebab imposed draconian restrictions on aid workers, blocking any effective assessment – there was no doubt the conditions in Afgoye were grim.
In May, AU troops fighting alongside government soldiers made their first major push outside Mogadishu and moved towards the town, with the majority of the Shebab fleeing ahead of the advance.
Now the rows and rows of wretched shelters made from scraps of plastic and twigs that line the route from Mogadishu to Afgoye stand almost empty.
“A very large number of IDPs (internally displaced people) in the Afgoye corridor were originally from Mogadishu and have returned there,” said Kilian Kleinschmidt, United Nations deputy humanitarian coordinator for Somalia.
The AU push out of Mogadishu, which began in early February, “was the floodgates opening”, Kleinschmidt said, as people who had been prevented from leaving by Shebab seized the first opportunity to flee.
At times as many as a thousand vehicles a day would ferry the displaced to the capital, although the United Nations still estimates as many as 120,000 displaced people could be left in the areas where their access remains severely restricted.
Not everyone, however, was heading back to Mogadishu.
Standing in the tin shack that serves as his office, Warsame Mohamed Siad said that after four years in the capital, he came back to Afgoye the day after the Shebab left.
Now head of customs for the fledgling government administration in the town, he runs the main checkpoint – a rope slung across the road surrounded by gunmen in mismatching uniforms – charging drivers anything from $0.50 to $20 to pass.
“We use the money for the government administration – for food, for the treatment of our wounded soldiers,” Siad, 40, said, as a queue of decrepit minibus taxis and brightly painted trucks waited to pass.
“We do not have any other sources of income,” he added.
The checkpoint was also a major source of income for Shebab when they controlled the town, but despite some residents saying that the government had taken over the role of extorting the population, Siad said things had changed.
“Yes, Shebab were also collecting money here but they would take hundreds of dollars, so it is a big difference,” he said, chewing on a stick of khat, a leafy plant containing amphetamine.
It was not just the people of Afgoye who suffered as a result of Shebab controlling the town – Afgoye was used as a base for the extremists to launch attacks on Mogadishu, AU commanders said.
The number of attacks “has dropped because we managed to capture those areas”, said Paul Lokech, commander of the Ugandan contingent of the 17,000-strong AU force.
It is hoped that securing Afgoye will therefore bolster security in Mogadishu, where the weak, Western-backed government ends its mandate on August 20, after eight years of infighting and minimal political progress.
But pockets of Shebab still regularly attack the road from the capital.
For shopkeeper Ibrahim, while business may be up, the government forces – often a hotchpotch of local militias – are struggling to maintain the security that Shebab’s harsh rule bought.
“Shebab were more disciplined – they didn’t come into town with gangs,” she said.
“But the government forces are here now and sometimes they fight each other and shoot and kill each other.”