After three years of drought thousands of colourful tents made with sticks and branches wrapped in plastic sheets and bits of cloth have sprung up among Mogadishu’s destroyed buildings. Over the summer and early autumn tens of thousands of starving Somalis entered the city. Now the refugees fill the shells of long-defunct ministries, gather in the shade of the roofless cathedral and stand under the parliament building like worshippers seeking a miracle. They appear in the streets in tattered clothing, holding bundles on their oversized heads, carrying yellow jerrycans and babies on their backs.

Inside the Ministry of Health, Fatima was building her tent, tying sticks together with strips of fabric, then wrapping larger pieces of cloth around them: a torn sarong, a plastic sheet, a fragment from an orange headscarf. Her infant son sat inside the tent with the rest of her possessions: a kettle and a blackened pot filled with half-cooked maize porridge that she got from a charity kitchen. She and her two sons would feed on that porridge for the next 24 hours, until she was given more. Around her many other tents filled the roofless room. Fatima’s tent stood against a shattered wall, its windows blown in by a tank shell some time in the last decade.

Fatima left her village in the south of Somalia, near Kismayo, when the rains failed for the third time. She walked to the nearest road, where she waited for a passing truck and begged a place for herself and her children. They travelled for three days in the back of the truck, surviving on the maize loaves she had with her and some water she begged for along the way. When they reached Afgoy on the outskirts of Mogadishu they were stopped by al-Shabaab militia, who told her to go back home. ‘They told us it was better to wait for God’s mercy and the rain than beg for food from the unbelievers.’ Twice she tried to cross into government-held territory, where aid was distributed, and twice they stopped her. She waited, but God’s mercy never came. A few days later she tried again, this time at night, and crossed the front line into the city.

Her older son was holding the sticks of the tent while she tied the knots around them and chattered away. ‘We left the sick and the old behind in the village. Only the strongest make it to Mogadishu: we were five when we left, now we are three.’ Where did the other two go? ‘I lost two sons,’ she said, and went on tying knots.

Three decades ago, Mohamed Siad Barre, commander of the Supreme Revolutionary Council, head of the politburo of the Somali Revolutionary Socialist Party and the last ruler of a functional Somali state, built vast concrete buildings all over Mogadishu. The beautiful city on the coast of the Indian Ocean, with its Arabic and Indian architecture, winding alleyways and Italian colonial-era villas, was dominated by these monuments. They were Third World incarnations of Soviet architecture, exuding power, stability and strength. The buildings – like the literacy campaigns, massive public works programmes and a long war against neighbouring Ethiopia in the late 1970s and early 1980s – were supposed to reflect the wisdom and authority of the dictator.

Sycophants and poets sang Siad Barre’s praises in these buildings, and schoolchildren waved ribbons and flew flags in their courtyards to celebrate his birthday. But in the deserts beyond the city walls nomadic tribes were agitating for war. When the Soviet Union fell and the unpredictable dictator could no longer play his hand in the Cold War game of African dictatorships, he was toppled. His clan was defeated by the clans he had marginalised.

Tribesmen poured into the city and Siad Barre’s state collapsed. The fighters ransacked Mogadishu’s Arab and European quarters and stripped its cinemas and ministries bare, shelled its old stone houses and hammered bullets into the walls and columns of its bars and cafés. Tribal commanders installed themselves as kings of crumbling neighbourhoods. Clan wars fragmented into sub-clan wars and then into sub-sub-clan wars. Tribesmen fought and killed other tribesmen and then turned against men of their own tribe and killed them. The fighters replaced their camels with Japanese pick-up trucks and fitted them with guns, turning them into war wagons. Everyone had been fighting for so long they forgot why they had started fighting in the first place and a miserable lethargy settled in. Generations of young men were born into the war, boys whose real mother was a Kalashnikov and whose only knowledge lay in the killing of other boys.

Twenty years later, Siad Barre’s monuments stand over a city of the dead and dying. They are landmarks in a battleground crisscrossed by front lines. ‘The Hotel Al-Uruba front line,’ people say. ‘There are food shipments at the Ministry of Health line.’ Trees and shrubs grow out of the broken walls and millions of bullets have marked the ruins with hairline cracks. You walk in fear of snipers and kidnappers and then a man comes up to you and points at a crumbling façade and says this was the Italian cinema, or at a pile of ruins on the beach and says that was Bar 54, the best bar in Mogadishu.

In the second decade of fighting, in 2006, when the warlords were exhausted after the long, incestuous wars, an alliance of Islamists called the Islamic Courts Union suppressed the warlords and brought a semblance of stability to Somalia. Most members of the Courts were traditional mullahs teaching the Quran in villages or local clerics dispensing justice according to sharia law in the absence of any other judicial system. Among the Courts there were few jihadis.

The Americans, pursuing their quixotic war on terrorism, hired some of the remaining warlords to work for the CIA, forming the Alliance for the Restoration of Peace and Counter-Terrorism. When the alliance was defeated by the Courts the Ethiopian army, with the blessing of the Americans, invaded to crush the Islamists. After fighting a vicious war for more than a year the invading army withdrew, leaving tens of thousands injured and maimed and thousands more dead, most of them civilians. Mogadishu was further destroyed – if that was possible – and tens of thousands joined the long caravan of Somali refugees driven from their homes by indiscriminate shelling.

A corrupt, dysfunctional, ‘transitional’ government was left to rule, guarded by African Union troops. But the worst outcome of the Ethiopian invasion was the rise of al-Shabaab, a small faction of the Courts at the beginning but a formidable power by the end of the war. They were supported by the Eritreans, the Ethiopians’ nemesis, and by 2009 controlled most of southern Somalia and Mogadishu.

That was the first year the rain failed.

Al-Shabaab ruled most of the city and their fighters were young. They imposed a brutal and arbitrary punishment code and beheaded their enemies. The government and its African backers controlled a small sliver of land to the west of the city and used it to try and shell the Islamists into submission.

The war continued and the rain failed again.

This summer al-Shabaab – weakened by internal divisions and the drought and under pressure from African Union troops armed with tanks and artillery – withdrew from Mogadishu. The government and African Union troops took over their positions but the rain refused to come and the city filled with the starving.

Badbaado means ‘salvation’ in Somali. It’s the name of a stretch of ruins and wild scrub on the outskirts of Mogadishu a few hundred metres from the closest al-Shabaab position. Thousands of tents fill the area: it is now the biggest refugee camp in Somalia.

A man in a green shirt and torn trousers crouched on the sand. He was thin but strong, his back and neck contoured with muscles. Around him sat his four daughters, two small boys, some bundles of cloth and a dozen yellow plastic jerrycans. His sister, tall with a grave face, stood over him, beside his two wives. He said his name was Omar Abdullahi and that they were hungry and tired.

Before the end of the third dry season, Omar Abdullahi lost all his cattle and his family finished the last of the grain he had not yet sold. He watched his crops wither and die in the drought. His land was less than half a kilometre from the Shabelle river, where the water was still flowing. The irrigation channels had been destroyed long ago and his maize and corn crops could only survive if he drew water from the river. But the water was controlled by rich banana planters from the Habar Gidir clan.

After the warlords and their clans had ransacked Mogadishu they moved on to the fertile farming land in the south, Omar’s land. The Habar Gidir, the strongest and most formidable of the clans, took over the lands upstream and drove away Omar’s tribe, a sub-sub-clan of the Rahanweyn. With water levels falling, the banana planters from the Habar Gidir diverted the flow towards their own lucrative banana plantations, the cash crop of Somalia exported mainly to the Middle East, even in the middle of a drought, while farmers like Omar who grew maize and sorghum for the local market starved and died.

Some Somalis say they have only themselves to blame. ‘The drought is affecting the whole of Somalia, so why is it that only the people of the south are dying?’ a man from the Abgaal clan asked me and then answered his own question: ‘Because they are not strong. They don’t care for each other. They settled, became farmers, became weak. They are to blame for their misery.’ In the long history of tribal wars in Somalia the southern Rahanweyn clan have always suffered at the hands of the strong nomadic clans of the north, who call them blacks, make fun of their accents, say they are not pure Somalis because they’re from the African south. And, when the war came, took their land.

For Omar it was all about water. ‘They built a dam,’ he said, ‘and would only allow the water to come to us once every six weeks. How can I water my crops once every six weeks?’ The farmers elected a committee to organise water distribution but al-Shabaab deemed it un-Islamic and banned it. ‘We went to the local al-Shabaab governor and complained. He said he would help us if we paid him money.’ Omar and others paid but no help came. Al-Shabaab needed the revenue generated by the taxation of the banana plantations and didn’t want to start a war with the Habar Gidir.

Omar filled his hand with sand and raised it and let the sand pour through his fingers. ‘My life.’ His sister stood by without moving, her eyes squinting and her mouth twisted in anger and hatred. Wrapped in her brown shawl she towered over her miserable family in silence. Even if rain fell now, and even if he could go back, it would take Omar years to rebuild his life and farm. In the meantime he is one of the many destitutes waiting for his daily bowl of rice.

I walked away from Omar and deeper into the camp. Long ago, before the clan wars, there had been villas here among the shrubs and trees. The Soviets built a veterinary school and experimental farms on this land. But the war destroyed all that, leaving only fragments of ruins, like fragments of a pulled tooth still wedged deep in the bleeding gum.

In a small orange and red tent a mother mechanically waved her hand over the piece of cloth that covered her infant child. With each wave two flies flew off in a buzzing circle and came back. The mother’s hand rested on her son’s motionless face and then swung back. The hand returned rhythmically like a pendulum and the two flies made their circle in the air again. Nothing else in the small tent moved. Everything was still, from the heat, dust and disease. The sun filtered through the cloth of the tent and everything was lit in orange, red and blue.

A few paces away from the tent, three men sat on the edge of a deep rectangular hole in the hot sand. They were burying the woman’s second child, a few metres from the shrub where they had buried her first. A man squatted inside the hole holding a small parcel wrapped in white cloth. Two of the men on top gave instructions and the third hissed long monotonous verses from the Quran. The man in the hole shuffled and jostled the head into a corner. It was small and knobbly and rested on his thick hand as he tried to push it inside a tiny niche. ‘A little to the right,’ one of the men said, and the verses cascaded into the hole.

A man started mixing sand and water further away from the hole and a bucket was filled and lowered to the man inside. A blue corrugated metal sheet was brought and put on top of the tiny corpse. ‘Hyenas,’ one of the men explained. They worked slowly, like the bored unemployed. They needed to do something useful to break the dullness of the long day.

They shuffled away, brushed the sand from their sarongs and sat under the shade of a tree a little way from the grave.

I went back to the mother, her hands still moving with the same rhythm, her face uncomprehending and dazed. She had walked for two weeks, she said. They fled the drought in the south and settled here, then a week ago a boy got measles in a tent over there, she said, and pointed. She looked up at me and her face showed some emotion. Since then, she said, nine children have died in that cluster of tents.

The father was with her elder daughter at the hospital. The doctor told them there was nothing he could do, that the child should be taken back to the camp. This wasn’t her only concern, though, since the hospital was several kilometres away and it would take her husband many hours to carry her back. She couldn’t leave her youngest child alone and that meant she would miss the daily distribution of food, a bowl of rice for each family every 24 hours.

Next to the mother’s tent, by a small intersection of collapsed buildings and dirt tracks, a woman had set up a shop. She had laid out her merchandise on a piece of wood: three onions, two heads of garlic and six tiny, well-wrapped, very precious bundles of maize.

I walked through the corridors of tents: coloured fabric, plastic jerrycans, a lonely pot, children naked or half-naked with swollen bellies and fathers long-limbed and knobbly-kneed. Ruins sprouted between the tents, blackened concrete and chipped plaster. Under my feet in the sand there were small pieces of marble floor.

At another cluster of tents a group of women sat on the sand outside, an infant pushing at his mother’s chest trying to feed from her shrivelled breasts. Their tents were surrounded by thorny shrubs and a small fence made of dried branches. ‘The fear came last night,’ they told me. They heard the screams of a woman in a tent nearby calling for help.

Did anyone help?

‘No one can leave their tents at night, the fear is everywhere.’

What about the guards, the government police?

‘The guards are the ones who rape the women.’

I find the raped woman sitting in her tent: everyone knew who she was. She was young, with plump cheeks and a distant look. She said that the previous night four men had got into the tent. Two dragged her husband away, putting a knife at his neck, and the other two raped her. Then the men swapped places. Her voice was thin and emotionless. Her hands settled on her long skirt, her long legs stretched in front of her. Her husband crouched behind her on the floor, his head lowered and eyes mesmerised by an imaginary spot on the ground.

‘This morning I went to complain,’ she said. She was taken to the hospital, examined and given six antibiotic pills. She showed me the pills, wrapped in a twist of paper. She hadn’t used them: she wasn’t sick, she had been raped. They also gave her an extra rice ration. The pot of rice was caked with a layer of black flies: blood money for her rape.

Not far from her tent hundreds of old men, women and children stood waiting in silence beside a barbed-wire fence. Behind it stood a line of gunmen in combat jackets, sunglasses and red caps. The mayor of Mogadishu energetically shouted orders and supervised the distribution of food. A visiting delegation from a Qatari charity was with him, watching and filming and snapping pictures. Their dishdashas, pouching out over their big bellies, were white, crisp and clean. The Qataris are among the biggest donors to Somalia and the mayor was keen to express his anger at the UN and the West. ‘Where is the UN, where’s the money, where are all those experts? They are all sitting in Nairobi, spending the aid money on supporting their own lives. They should be here, working.’

The people filed past the mayor and his dignified guests. They collected their rations and walked out, like children on their best behaviour in front of a family friend. Satisfied, the mayor and his guests drove away, followed by four pick-up trucks with machine-guns, and the gunmen to man them. Before the dust from the mayor’s trucks had settled other people were pushing at the barbed wire and scrambling for any food that was left.

At another food distribution centre, on the southern edge of the camp, there were similar scenes: men, women and boys pressed against the fence, the barbed wire ripping their clothes. Guards beat them back with sticks and waved guns at them but they pushed harder. Inside the barbed-wire enclosure two men used shovels to scoop rice from a huge black pot and fill the bowls and pans and plastic bags extended to them by starving people crushing each other as they pushed closer to the rice.

A tall woman in a pink headscarf lashed at them with a thick stick, raising it high and then landing a blow on someone’s head or chest. After a few blows she raised her fat leg and kicked an old man in the chest, sending him scrambling into the dust. The crowd opened for him to fall and then closed in on the rice again.

‘I said: only women will be served here,’ she shrieked and yanked at the hair of the fallen man. ‘You filthy men will eat all the food on your own.’

When the pot was empty and there was no rice left to give and when the men with shovels had moved on, children stormed around the empty pot, pushing half their bodies inside, scooping at the few grains of rice that remained.

The district chief of Badbaado sat on a plastic chair, his belly huge, his beard dyed orange with henna. Next to him sat the district police chief, a small man dressed in commando fatigues. They were flanked by dozens of armed guards, the same men who had raped the young woman and who a week earlier attacked an aid convoy, taking the food and killing eight refugees. The district chief is a former warlord. He and others allow the refugees to settle on their land and in return take a share of the aid. The guards have a free hand extorting money from the refugees they are supposed to protect.

The next day I met the mayor of Mogadishu in his office. A few blocks away, in the Hamar Weyre district of the city, people had been demonstrating against another district chief, shouting: ‘Get rid of the thief!’ The mayor told me he knew what was happening and said the men would be replaced. He was referring to the Badbaado and Hamar Weyre district chiefs, but he doesn’t have the power to touch either man, whose forces easily outnumber his.

I watched as a truck loaded with food was driven into a school where refugees waited for hours for it to be handed out, only to be told that it wouldn’t be distributed until the following day. The next day they went back to find that most of the food had been looted.

In the middle of a famine, Mogadishu is a perfect place to set up a business. International aid organisations need warehouses for their food and guards and drivers for their staff. Somali businessmen are importing food supplies to sell to Arab charities that want to feed the Somalis but don’t have the means to bring in their own supplies.

The UN says six children are dying every day, and one of the places in which they are dying is Banadir Hospital. The wards, corridors and waiting areas were full of tired, bored and grieving mothers and their dying children, emaciated and stunned. They sat on the floor against the filthy blue chipped wall. The head of a child rested on the long flower-patterned dress of his mother, his eyes half-open and showing only thin slits of white. When he breathed a tiny hissing sound came from his mouth. He was wrapped in flowery fabrics, with a bottle of water and two sachets of salt formula next to him. The mother rested her hand on her leg and watched him.

Across the room on a bed below a window, a child was twisting and crying. His limbs were very thin, his face was like a skull and his eyes were sunk deep in his head. He was kicking his legs, his ribs drawn deep. He screamed for water. The mother peeled a banana and offered it to him but he pushed it away: he wanted water. The mother, tired of his screaming, reached down to get a plastic bottle of water but the husband shouted at her: he wasn’t allowed too much water.

Next to him two children slept on a cholera bed with a hole in the middle, lying back to back. Their garments were wet and dangled into a plastic pot filled with their watery faeces.

At the end of the corridor another young woman was wrapped in a red shawl clutching an empty packet of medicine, her eyes open and staring. A tall Sudanese doctor was walking from one bed to another. ‘He is doing fine,’ he told a woman in Arabic as she clutched her child.

He turned to the medic next to him and said to him in English: ‘Ask her where she put the medicine I gave her last time.’

The medic asked the woman in Somali. She didn’t know. She fiddled in the sheets the child was wrapped in but the doctor couldn’t wait: others were calling for him.

He tried to insert the tube for a drip into a child’s skull. I asked him: why not his hand? He looked at me, lifted the child’s tiny hand and said: ‘Find me a vein here and you can have my lunch today.’ He told me he’d been at home in Khartoum watching al-Jazeera when he saw what was happening in Somalia. ‘I knew I had to come. I had seen this before, in Darfur. But this is mad. People are leaving their polluted faeces on the ground and then drinking water from the well next to it. It’s mad. With a water purification unit I could cut cases of diarrhoea in half.’

Later he whispered: ‘I have to talk to you. I have to talk or I’ll explode.’

The next day I went to see him at his residence. He was flanked by two PRs from his NGO. Eventually they got bored and left us alone together.

‘Look, what’s happening is wrong. We have many doctors, Egyptian and Saudis. They are all well intentioned but they haven’t seen malnourished babies before. I need WHO doctors. They had them in Darfur. They have portable labs, they could do tests to find out what we are dealing with in the hospital. I still don’t know how many measles cases I have. I arrive every morning and I see 50 new cases. Where did yesterday’s cases go? Did they all get better? Did they all die? I don’t know, no one knows, there is no co-ordination. The Saudis brought us hundreds of crates of water but I don’t want bottled water, it will just get stolen by the guards and management. I want a water purification unit.’

Back in the hospital a man sat on a piece of soiled cardboard, holding his son’s head high, a tube inserted into the child’s nose. A visiting delegation from an Arab charity passed by. They went up to the father and his child, and a man in a white jacket with the charity’s logo kneeled next to the child. The father looked at him respectfully while he held the child’s head and turned to face one of his colleagues, who was holding a camera. The man grinned, and the other man took his picture.

‘OK, Muhammad, it’s your turn,’ the kneeling man said, and they switched places.