Somalia is one of the most extraordinary places on Earth, its people no less remarkable. In theory it should be the most united country in Africa. Somalis share one language, one religion and one culture. Yet, in practice, they are probably the most divided nation on Earth, doomed to rifts by a clan system exploited by unscrupulous leaders and an apparent inability to agree on anything. It is to Andrew Harding’s credit that he manages to get under the skin of this complicated, perplexing, often maddening country that foreigners struggle to understand.

The story centres on a charismatic protagonist. Nicknamed Tarzan during his childhood in an orphanage, Mohamoud Nur became a Somali celebrity as the mayor of Mogadishu from 2010-2014. To call him a divisive figure would be an understatement. Harding, the BBC’s Africa correspondent, who has been visiting Somalia since 2000, provides a neat summary of the competing views of this most controversial of politicians.

“He’s a thug, a shallow charmer, the only honest politician in town, a useful whirlwind, a slave to his own clan’s interests, a corrupt hypocrite, a cheap populist, Somalia’s future president, a media sideshow, the diaspora’s darling, the city’s saviour.”

Perhaps he was all of the above – a man of and for his time. One of the most admirable traits about Somalis, although it shades into one of their least commendable – the propensity for conflict – is their fearlessness. Nur exhibited it in spades at a time when the terrorists of Al Shabab controlled most of Mogadishu. This is a man who stared down the lens of television cameras and challenged the nihilistic beardies to do their worst. “Don’t disguise yourselves as women. Don’t hide your weapons under your clothes. Come for me in the open and then kill me, if you can.”

They couldn’t.

In many countries, Nur’s hardscrabble backstory would be considered tragic and exotic, with a whiff of romance about it. For Somalis it is utterly unexceptional. Given away by his impoverished mother after the death of his father, he was handed over to an aunt thence to a tough-­as-old-boots orphanage. Orphans were looked down on with derision, as the weak and vulnerable often are in Somalia – “They call us bastards. Fatherless bastards”. His escape to the United Kingdom, where he emerged as a combative, can-do community leader, mirrored the flight of one in seven Somalis – perhaps a million – from the chaos of the civil war, which either lasted from 1991 to 2011 or is still ongoing, depending on your view.

Nur can be accused of many things, but a fence-sitting reluctance to speak his mind come what may has never been one of them. At a conference in Morocco for American and Arab mayors, he asked if any city wanted to be a sister to Mogadishu. The room was silent in response. “If you’re poor, they step on your head,” he tells Harding by way of explaining the Arab reaction.

It is a quintessentially Somali remark. If there is one thing that binds this fractured nation together, it is the complete conviction that Somalis are the greatest people on Earth. Other Muslims are second-class citizens. Black Africans are jeered at and called names. Whites are beyond the pale. That the superiority complex owes nothing to reality is besides the point. Somalis are the toughest people in the world and therefore the best. As a communications adviser to the prime minister and president, based in Mogadishu from 2013-2014, I was often introduced to ministers and senior officials as “my White Nigger” by one of my more high-spirited colleagues.

Somalis are extremely hard on each other. It is one of the main reasons the country is in such a mess. Discussing their astonishing proclivity for argument over the most minor matters, Harding writes: “No topic was too small to trigger a row”. He describes a meeting of Mogadishu’s 16 district commissioners torpedoed by a furious row over biscuits.

Harding writes with great empathy about Somalia and its people, eschewing the lazy generalisations common to much western journalism about Africa, which is either “doomed to fail or rising like a phoenix”. Foreigners who live among Somalis tend to experience the full gamut of emotional reactions – from exhilaration and frustration to disbelief, angst, anger and affection. Harding cites the verdict offered by Gerald Hanley, author of Warriors, one of the finest books on Somalia in the English language, that “of all the races of Africa there cannot be one better to live among than the most difficult, the proudest, the bravest, the vainest, the most merciless, the friendliest: the Somalis.” Those who know the country would tend to agree.

Power corrupts as much in Somalia as anywhere else and Nur is no exception to the rule. “Anyone against me is a bad person,” he tells Harding after he has been sacked as mayor. “Whoever is on my side is in the right. Whoever is against me is wrong.” There in three sentences is a microcosm of so much that is wrong about politics in Somalia. One can imagine the same words from Siad Barre, the dictator from whose stubborn misrule the country is still suffering a quarter of a century after he was forcibly removed from office.

The Mayor of Mogadishu is much more than the story of one ambitious Somali politician. It is the modern history of one of the world’s most troubled country, told with sensitivity, wisdom and compassion – and a rollicking good read besides.

Justin Marozzi is a freelance journalist and author of Baghdad: City of Peace, City of Blood, winner of the 2015 Ondaatje Prize.