“Don’t worry,” shouted one, “it’s one of our snipers. He’s firing at a guy on the other side aiming an RPG at us.”

Welcome to life on the front line in Mogadishu, the capital of Somalia, a city regularly described as the most dangerous on Earth.

The Ugandan soldiers protecting me were peacekeepers from an African force called AMISOM, which has been given the tricky job of retaking the world’s most devastated country from warlords and Islamic militants attempting to introduce Taliban-style rule.

Conflict has raged in Somalia for decades. In the 1970s and 80s it was ruled by a dictator, then in 1991 there was a civil war after which the government collapsed and warlords took over.

There’s since been appalling famine. Foreign attempts to save the country have failed. At least one million people have died and piracy has flourished.

I was visiting Mogadishu while travelling around the edge of the Indian Ocean for my new BBC TV series.

My journey took me from South Africa up the east of Africa, around India and back down through Indonesia to finish in Australia.

Travelling to Somalia was the most dangerous leg of the journey. It is the source of a piracy epidemic affecting the whole of the western Indian Ocean.

It was somewhere I felt I had to visit.

With cameraman Jonathan Young, and director Andrew Carter, I flew in from Kenya, and was greeted by brawling at the airport.

Tough: Mean streets seen from inside an armoured car

An AMISOM official smiled as a man fought with a policeman from the fledgling Somali government. “Par for the course here,” he said sadly.

The airport is inside a protected military base but even there we didn’t feel entirely safe.

AMISOM is backed by the UN and indirectly by money from the West.

Since 2007 it has been locked in a bitter struggle with al-Shabab, a heavily-armed, exceptionally violent Somali Islamic group linked to al-Qaeda, which takes a cut from pirates.

Al-Shabab still controls most of the country, terrorising its own people, and is fighting a terror war against AMISOM.

A few nights before we arrived an intruder got over the wall of the base and was shot dead. Then another intruder was captured.

He confessed to being a member of al-Shabab who had a GPS locator to identify targets inside the base for attacks.

Early the next day we prepared to head out into the city with flak jackets, helmets, medical trauma kits and even Blast Boxers, a type of armoured underwear troops wear to prevent shrapnel injuries to the groin.

So to get around we needed to travel in two huge armoured personnel carriers.

Just before our visit a powerful roadside bomb had devastated the inside of an APC vehicle.

The Ugandans were jumpy and loaded Kalashnikov assault rifles were mounted inside.

“I hope it doesn’t come to this, but do you know how to flick the safety catch off?” asked Lieutenant Colonel Paddy Ankunda.

We headed into the devastated city.

Some grand colonial-era buildings are still standing but I was reminded of images of Second World War Stalingrad or Grozny, with everything riddled with bullet holes.

As we drove around we could see people shopping in markets or fetching water.

Some areas looked deceptively calm, but militants and gunmen hide among the local population, and it was too dangerous for us to leave the APCs for more than a few minutes.

“Everyone has guns here,” said Paddy. “We stay too long, and a gang will arrive to fight us for you.”

Safety first: Simon takes advice

We visited several areas on the front line where 9,000 Ugandan troops are fighting al-Shabab.

The fighting was often house to house, or garden to garden, as AMISOM soldiers advanced through the suburbs of the ruined city.

As I talked with Paddy, the Ugandans spotted al-Shabab fighters preparing to launch rocket-propelled grenades at us and opened fire.

I had to pinch myself as a reminder it was the 21st Century.

The shooting intensified and Paddy decided to pull us out of danger.

We were bundled back into the APCs and driven to the former Somali national stadium, which al-Shabab used for public executions.

“This should be Highbury, the Emirates,” said Paddy, as we walked around the derelict stadium.

A donkey grazed on the ragged pitch and a collection of ramshackle pick-up trucks with anti-aircraft guns on the back, surrendered by a warlord, stood forlornly at one end.

I was in Mogadishu a few years previously for another BBC series and was protected by a dozen stoned local mercenaries.

It was even more dangerous then, completely anarchic.

This time I could see a few signs of improvement with shops open and fewer guns on the streets.

But Mogadishu is still in a desperate state.

The only solution seems to be to support AMISOM and the fledgling Somali government in their battle to stabilise the country.

Since my visit they have pushed al-Shabab outside the city.

But dozens of Ugandans have died battling to save Somalia with inadequate backing.

They don’t have a single helicopter. They need airpower and thousands more troops.

With more support from the international community it’s just possible the militants could be defeated, that Indian Ocean pirate attacks could be halted, and that Somalis could have the long-term stability they so desperately need.