ACCORDING to Ronald Reagan, he was a "mad dog". Former Egyptian president Anwar Sadat at first saw his neighbour as "a bit of a boy scout", before changing his mind, denouncing him as "100 per cent mad".

Colonel Gadaffi may like to style himself as the Libyan Leopard, but it seems few others have a good word to say about him.

Or at least they didn't. Now he is "courageous" and "statesmanlike", the author of an "extraordinary" revival in his country's fortunes on the international stage. He may have already met the Italian and Spanish prime ministers, but yesterday's handshake with Tony Blair, ending 20 years of hostility between the UK and Libya, was far more significant, and completes a truly remarkable journey for the eccentric dictator.

From international pariah, ridiculed, ignored and despised in equal measure, it seems Gadaffi has now become an accepted member of the community of nations, a leader no longer banished to his tents in the desert, but fit to take his seat at the conference table, a phenomenal transformation even by the singular standards of his 34-year rule.

Blair's visit, the first to Libya by a British prime minister since Churchill in 1943, seems to be a reward for Gadaffi giving up his efforts to acquire weapons of mass destruction. News of that decision, announced by Blair to an astonished world at Durham Cathedral last December, was the culmination of lengthy efforts from Tripoli to end its international isolation.

And the rewards for Libya are not just those of diplomacy, but will also bring a desperately needed end to its economic exile, which has seen an oil-rich country stagnate while its neighbours and rivals moved forward. Although US sanctions remain in force, Blair's visit was preceded by that of US Assistant Secretary of State William Burns, the most senior American to set foot in Libya since Gadaffi came to power in 1969.

In those days, Gadaffi was a humble captain, a 27-year-old officer who led a coup against Libya's King Idris. A follower of Egypt's Colonel Nasser, Gadaffi proceeded to rule with a combination of Arab nationalism, socialism, Islamic fervour and the money from Libya's vast oil reserves. Among his first acts was to shut all of Tripoli's nightclubs and turn the city's cathedral into a mosque, but as his rule developed it became more idiosyncratic. He set out his philosophy in his Green Book, published in 1972, which includes the revelation that both men and women are human beings.

Gadaffi is said to have been born in a tent in Libya's northern wilderness, but was sent to school on the coast, although later expelled for organising a demonstration. He dropped out of university and joined the national military academy, where he was inspired by Nasser's dreams of a resurgence of Arab glory. On Nasser's death, a year after Libya's coup, Gadaffi appointed himself the Egyptian leader's successor as custodian of Arabism.

And aspirations to create a pan-Arab state occupied much of his early years in power. He proposed mergers with several of his neighbours, but when these overtures were rebuffed he proceeded to antagonise first the rest of North Africa, and then the rest of the world.

He spearheaded his own cultural revolution, removing all trace of the imported ideologies of capitalism and communism, and building a society based on his own version of socialism. But the result was that Libya's vast wealth was squandered, on grandiose projects including a $6bn attempt to bring underground water from the desert to the coast, on constructing an economy where profit was banned and so supermarket shelves stood empty, and most of all on shoring up his regime, either through repression at home, or pouring money into defence.

ACCORDING to Amnesty International, the torture of political opponents was routine, and there were televised hangings of those accused of trying to undermine Gadaffi's rule. A journalist, critical of Gadaffi, was shot outside the Regent's Park mosque in London, and for all his avowals that Libya was "a state of the masses", for which he even coined a new Arabic word, power remained resolutely concentrated in his hands.

It was perhaps the next step from domestic repression to supporting terrorism abroad. His desire to destroy Israel and safeguard the Arab world from the evil influence of the West saw him lend financial support to Palestinian groups, responsible for a series of attacks in Europe. It was the bombing of a Berlin nightclub in 1986 which prompted US airstrikes on Libya, taking off from British bases, killing 40 people, including Gadaffi's adopted daughter, but narrowly missing the dictator himself. It was said to be in retaliation for this attack that a Libyan bomb downed Pan Am flight 103 over Lockerbie in 1988, killing all 259 people on board and another 11 on the ground. It is still the worst terrorist atrocity committed on European soil.

Gadaffi was also accused over the killing of WPC Yvonne Fletcher, shot dead outside the Libyan embassy during a demonstration in London in April 1984. The gunman was smuggled out with other staff under diplomatic immunity.

But it was his support for the IRA which has left the most far-reaching legacy on these shores. It was Gadaffi's oil money and steady supply of weapons and explosives which turned the IRA into one of the world's wealthiest criminal organisations. Throughout the 1980s, Gadaffi is thought to have given the IRA £6.75m in cash, ten tons of Semtex explosive, and cases of AK-47 automatic rifles.

Recent years have seen an about-turn on the part of the Libyan Leopard, with a series of moves to effect a rapprochement with his one-time sworn enemies. In 1999, after lengthy diplomatic manoeuvres, the two suspects for the Lockerbie bomb were handed over for trial - one of them is now serving life in a Scottish prison. Last December came the renunciation of efforts to acquire WMD, and yesterday's visit was accompanied by the news that Metropolitan Police officers will be allowed into Libya to investigate WPC Fletcher's murder.

While the speed of recent developments may have much to do with a desire not to be next on President Bush's hit list and go the same way as Saddam, Gadaffi's desire to improve relations with the West can be traced to long before the war on Iraq. He was the first Arab leader to condemn the September 11 attacks, a sign of how far he had moved from his previous beliefs.

Perhaps he has grown weary of his international isolation, and frustrated at being ignored for so long, and there is also speculation over his health, with the possibility he is trying to ease the transition of power to his son and heir apparent, Saif al-Islam Gadaffi.

BUT probably the key factor is that Libya has grown weary of economic hardship. Sanctions have taken their toll, and the country of just five million people has seen living standards stay still despite its oil wealth. The benefits of opening up trade with the West are potentially enormous, both in access to US technology and to international markets: the £1.7bn compensation paid to relatives of the Lockerbie bomb will be recovered in just 20 months.

For Blair and the West, Gadaffi's conversion is a chance to show the benefits of towing the line, on giving up WMD and renouncing terrorism, a sign that the Arab world can be accommodated within Bush's vision, if only it plays ball. The economic rewards are two-way as well - Shell yesterday announced a £550m deal for gas exploration rights off the Libyan coast, and US companies can expect to take up their oil concessions once sanctions are finally lifted - but it is clear the primary motive is political.

That handshake shows that there is a way back from the Axis of Evil, that it is possible to come off the US list of countries which sponsor terrorism. It shows to the electorates of the West that the war on terrorism does not have to involve violence, and it shows to those states still counted as rogue - North Korea, Iran and Syria in particular - that if they co-operate their regimes can remain intact and their countries unspoiled. If Saddam was an example of what happens when you cross the West, Gadaffi may be an example of what happens if you behave.