With good reason Nelson Mandela was known and revered across the world for his saintliness, his personal courage and his leadership qualities.

Closer to home, though, he was an uncomfortable icon because those were the very qualities that were missing in many other leaders of emergent African countries.

Throughout his lifetime, the history of sub-Saharan Africa was littered with examples of countries becoming independent under "big men" leaders who came to power vowing to liberate their people from the tyranny of the colonial past but then became dictators, seizing power for themselves and their families and usually using the rhetoric of liberation to justify their actions.

Whatever Mandela's faults, and his period in office was not an unalloyed triumphal progress, no-one could accuse him for not leading by example. He could have become president for life but he did not, preferring to accept only one term in office and standing down at the end of the century, thereby setting a peerless example and at the same time sending a silent rebuke to his fellow African leaders. His philosophy was summed up in a ground-breaking essay in the influential Foreign Affairs magazine in 1993.

"South Africa's future foreign relations will be based on our belief that human rights should be the core concern of international relations, and we are ready to play a role in fostering peace and prosperity in the world we share with the community of nations. We are well aware how important and how difficult the process of reintegration into the global political and economic system will be for South Africa."

As events were to show, that precept was never followed, with the result that much of post-colonial Africa became subject to murderous and self-centred leaders who regarded their countries as their personal fiefdoms. They might have paid lip service to Mandela and his principles but they certainly did not follow them. The current fighting in the Central African Republic is grim testimony to that example.

Elsewhere in the world it was somewhat different and Mandela emerged as a leading player on the international scene and as a diplomat who had a lifetime's experience to offer. Given his reputation as a freedom fighter and the example of his "long walk to freedom" it was not surprising that many leaders or would-be leaders wanted to hang on to his coat tails. This was especially true in parts of the world where people attempted to forge a relationship with him on account of alleged similarities between their own struggles and Mandela's opposition to the apartheid regime in South Africa.

In the period between Mandela's release in 1990 and his final withdrawal from public life in 2004 this kind of diplomacy tended to raise hackles in Western capitals, where some politicians could never forget that he had been a convicted terrorist. In Washington, there was considerable irritation over Mandela's support for President Fidel Castro of Cuba and President Muammar Gaddafi of Libya, while in London there was exasperation in Conservative ranks because he appeared to be in favour of the armed struggle conducted by the Provisional IRA in Northern Ireland. So profound was that belief in unionist circles in the 1980s that the late Frank Millar, a senior Ulster Unionist Party politician dismissed Mandela as a "black Provo". The tone was also reinforced by Prime Minister Margaret Thatcher, who repeatedly refused to visit Mandela while he was in prison on the grounds that "the prime minister does not speak to terrorists".

As for Mandela, he encouraged the formation of political links between the African National Congress (ANC) and Sinn Fein. He was also in favour of establishing connections between the ANC's guerrilla wing Umkhonto we Sizwe and the Provisional IRA, which provided military assistance and advice during the late 1970s. In 2000, Mandela caused a sensation when he told a private meeting of Irish newspaper editors in Dublin that he was against the idea of the IRA surrendering or decommissioning its arsenal on the grounds that "you don't hand over your weapons until you get what you want". His official view, though, was that he welcomed the talks with Sinn Fein and that talking, not violence, would be the only way to resolve the long-standing problem in Northern Ireland. In 1997, he put that philosophy into action when he agreed to host a conference between the parties in Cape Town so that they could get away from the pressures of Belfast.

However, what touched Mandela even more deeply was the plight of the Palestinian people, famously saying after he came to power: "We know too well that our freedom is incomplete without the freedom of the Palestinians."

Mandela met the late Palestinian leader Yasser Arafat on several occasions and when he received the news of his death in 2004, he said: "Yasser Arafat was one of the outstanding freedom fighters of this generation, one who gave his entire life to the cause of the Palestinian people."

Needless to say, comments like that were not designed to appeal to the Israelis or to the US but Mandela was unafraid to voice his opinion about what he believed to be Israeli repression of the Palestinian people and Washington's support for that policy. In 2003, prior to the US-led invasion of Iraq under the leadership of President George W Bush he criticised both the US and the UK for holding "racist attitudes" towards Iraq, pointing out that they did not criticise Israel for having weapons of mass destruction, because Israelis were seen as "white", while Iraqis were seen as "black".

In making those comments, Mandela was always careful to make a distinction between Jewish people and the state of Israel, seeing them as two separate entities. In his early days when he was making his way in life he remembered with gratitude the help he had received from members of South Africa's Jewish community, notably ANC supporter Arthur Goldreich, who gave him a job as a lawyer. Mandela later said: "I owe a debt of honour to the Jews even if I have sometimes made restrained remarks about Israel."

Elsewhere in the Middle East, one of Mandela's first visits after his release was to travel to Libya to thank President Gaddafi for his unbending support for the ANC, providing funds, training and weapons to the armed wing. Four years later, in 1994, Gaddafi was an official guest at Mandela's swearing in as president. The gesture was all the more remarkable because at the time the Libyan president was a pariah in the international community. When Western governments made clear their displeasure, Mandela responded: "Those who feel irritated by our friendship with President Gaddafi can go jump in the pool."

So important was that connection that one of Mandela's grandsons is named after Gaddafi. Not for the first or the last time the newly elected South African president demonstrated that behind his courtesy and his frankness he had a spine of steel and would not be bullied. To him it was quite simple: while the West had done very little to shackle the apartheid regime in South Africa, Libya had been a close ally and supporter of the ANC and it was unthinkable that the friendship should cease. As ever, though, Mandela was not just following his heart: there was a purpose to his diplomacy. Far from following a personal whim, Mandela played a key role in ending Gaddafi's isolation by brokering a deal with the UK over the 1988 Lockerbie bombing.

Under its terms Gaddafi handed over the two leading suspects, Al Amin Khalifa Fhimah and Abdelbaset Ali Mohmed al-Megrahi, for trial by a Scottish court. The former was acquitted and returned to Libya but Megrahi was jailed for life. At the time that the two men were handed over for trial, Mandela claimed that it was one of his biggest foreign policy achievements and that it underlined the importance of maintaining an independent foreign policy.

"No-one can deny that the friendship and trust between South Africa and Libya played a significant part in arriving at this solution," he said in 1999 as he approached the end of his presidency. "It vindicates our view that talking to one another and searching for peaceful solutions remains the surest way to resolve differences and advance peace and progress in the world."

Eight years into his sentence Megrahi was released by the Scottish government on compassionate grounds, a decision that was also welcomed by Mandela. In a world in which hard-nosed politics usually takes precedence over humanity and common sense that kind of universalism, backed by strong moral values, is going to be badly missed