It will be 350 years ago in January that Oliver Cromwell was convicted of treason and posthumously beheaded. But who was this reluctant republican – and could he be the greatest politician in our history?

Wednesday 30 January 1661: the Old Bailey, London. At the Bar, four bedraggled men await sentencing for treason. As the judge pronounces the death penalty, they show not a flicker of emotion. Not even a muscle twitches to show their fear. But why would it? Oliver Cromwell, Henry Ireton, John Bradshawe and Thomas Pride are dead already. Wrapped in shrouds, their corpses have been propped up against the Bar in a ghastly parody of justice.

When the judge orders them taken down, they are hauled back to their coffins and dragged on sledges through the streets to Tyburn. There, in front of a vast crowd of men, women and children, the bodies are hanged by the neck, dangling limply in their rags. At sunset they are taken down and their heads are cut off and stuck on poles above Westminster Hall.

The head of the most controversial figure in British history, severed from his dead body almost 350 years ago today, remained one of London's more grotesque attractions for several decades. Some time in the late 17th century it was recovered by a soldier, became a bizarre collector's item, and was finally buried in Cromwell's old college, Sidney Sussex, Cambridge, in 1960. For a man who had been Lord Protector of England, Scotland and Ireland, victor of Naseby, Worcester and Marston Moor, one of the architects of British sea power and the only commoner in history to serve as our head of state, it was a demeaning end.

And yet, in some ways, the strange story of Cromwell's head - which may not even be his, as some still think that his body was switched for another before the gruesome ritual at Tyburn - is an appropriate epilogue to an extraordinarily ambiguous career. The king-killer who toyed with wearing the crown, the hero of liberty who shot down the Levellers, the champion of religious toleration who loathed Catholicism, the practical joker who became a symbol of joyless Puritanism, he remains one of the most bewildering figures in British history.

By any standards, the former yeoman farmer from Huntingdon in Cambridgeshire is one of the most notable - perhaps the outstanding - figure in our national story. If, as the celebrated Marxist historian Christopher Hill wrote in his splendid God's Englishman (1970), "the 17th century is the decisive century in English history", then Cromwell is its dominant player.

In Ireland he is still hated; in Britain, however, he has admirers at both ends of the political spectrum. Michael Foot used to write irate letters to newspaper editors whenever his hero was criticised, while the right-wing columnist Simon Heffer ranks Cromwell next to Gladstone and Thatcher as one of the greatest leaders in British history.

What makes Cromwell's rise to power so fascinating is that it came so late. When the civil war broke out in 1642, he was already 43 and had achieved virtually nothing of note. A distant descendant of Henry VIII's reforming minister Thomas Cromwell, he spent most of his first four decades hovering on the fringes of the gentry. "I was by birth a gentleman," Cromwell said later, "living neither in any considerable height, nor yet in obscurity." But because his father was a younger son in an age that rewarded seniority, the Cromwell family suffered from perennial money troubles, and although Oliver entered Cambridge in 1616 and married a merchant's daughter, his status remained precarious.

In 1631, when he was in his early thirties, he sold most of his properties in Huntingdon and became the tenant of a small farmstead in St Ives - clearly a step down the social ladder. Even years later, his royalist opponents could barely contain their horror that such a man had once been the ruler of all Britain. He wore "a plain cloth-suit, which seemed to have been made by a poor tailor", sniffed the Old Etonian Sir Philip Warwick, recalling Cromwell the young man. "His shirt was plain, and not very clean; and I remember a speck or two of blood upon his collar . . . His face was swollen and red, his voice sharp and untunable, and his speech full of passion."

One of the many misconceptions about Cromwell is that he was a dull, dour man, the kind who liked nothing better than smashing up stained-glass windows and banning Christmas. Nothing could be further from the truth. As a boy, writes Hill, Oliver was "rough, boisterous and practical-joking", and even as MP for Cambridge he was generally regarded as outspoken, impetuous and politically naive.

Far from being solemn, he was an ebullient, fun-loving man who wore his hair long, smoked tobacco and enjoyed a drink. At the wedding of his daughter Frances, after he had become Lord Protector, Cromwell reportedly tossed wine over his guests, danced until dawn and "dawbed all the stools where they were to sit with wet sweet-meates", rather like some early-modern Benny Hill. Given his wild mood swings between jubilation and gloom, some biographers have suggested that he suffered from manic depression, which might explain why he laughed "as if he had been drunk" after the Battle of Dunbar in 1650, or why, at the signing of Charles I's death warrant, he relieved the tension by flicking ink at his colleagues' faces, like a naughty schoolboy.

To modern eyes, however, Cromwell can often seem almost an alien figure. In many ways, what defined him was his burning religious passion, the kind of thing we now associate with the drive-in churches of the American South rather than the flat world of the East Anglian fens. It seems clear that around 1629 or 1630, when his financial woes were at their worst, Cromwell came close to a mental and physical breakdown. His doctor in Huntingdon said later that Cromwell had a "strong fancy" that "he was dying". In any case, he went through a process that we would call being "born again", becoming convinced that God had marked him out for eternal salvation.

“Oh, have I lived in and loved darkness and hated the light," he wrote a few years later. "I was a chief, the chief of sinners . . . I hated godliness; yet God had mercy upon me. O the riches of His mercy!"

To describe Cromwell as a religious fun­damentalist slightly misses the point. Fundamentalism originated as a response to secular modernity; by contrast, Cromwell was born into a premodern world that took religious assumptions extremely seriously.

What marked him out was not so much that he was very religious, but that he belonged to a particular group - the "godly", whom we call Puritans - who believed that Charles I and his courtiers were betraying the potential of the Protestant Reformation.

To men like Cromwell, the sinister armies of international Catholicism were permanently poised to strike across the Channel and extinguish English Protestantism for ever. We might well regard them as paranoid; but to those who could recall the Spanish Armada and the Gunpowder Plot, and who were horrified by news of the Thirty Years War, such fears seemed all too realistic.

By the summer of 1642, the fears that had built steadily over so many years were near their peak. A Scottish revolt at his proposed new prayer book in 1637 had been followed by rebellion in Ireland, and Charles I was forced to summon parliament to raise new taxes. Relations soon broke down, however, and in January 1642 his half-hearted coup, in which he led troops into the Commons in pursuit of his chief critics, had destroyed any chance of a compromise.

Even at this stage, Cromwell was a relatively obscure figure. His financial woes were over, thanks to an inheritance from his uncle which allowed him to rejoin the ranks of the East Anglian gentry, and in 1640 he was elected MP for Cambridge. But although he was identified with the opposition to the king, he was hardly a household name, merely a backbencher with good contacts. What marked him out was his sheer belligerence. Ten days before war had even started, he seized the arms store at Cambridge Castle and intercepted an armed escort taking money from the university to the king. Had the conflict fizzled out, he would have been guilty of robbery and treason. Not for the first time, he had gambled -and won.

War was the making of Oliver Cromwell. Like many other Puritan MPs, he was raring to take the fight to the enemy, recruiting a cavalry troop in Cambridgeshire and taking part in the first battle at Edgehill, Oxfordshire, in October 1642. Despite his lack of military training, he proved a highly successful cavalry officer, rising to lieutenant general in the army of the Eastern Association and then second-in-command of the New Model Army. Besides giving him a national presence, the war shaped his career in two decisive ways.

The first was his unusually close relationship with his men. Renowned for his stern discipline - not for nothing were his troopers nicknamed Ironsides - Cromwell took his responsibilities to his men very seriously indeed, championing their demands for better pay.

Unlike other commanders, he refused to promote men for reasons of birth and breeding; his officers, sneered the Earl of Manchester, were "common men, poor and of mean parentage". Cromwell was unrepentant, however: as he famously wrote in 1643, "I had rather have a plain russet-coated captain that knows what he fights for and loves what he knows, than that which you call 'a gentleman' and is nothing else." Many of his officers were humble yeo­men, picked for their religious zeal. "I have a lovely company," he told a friend, calling them "honest sober Christians". They were holy warriors: if they were "well armed within by the satisfaction of their conscience", he thought, "they would as one man stand firmly and charge desperately".

The second effect of the civil war was to strengthen Cromwell's sense that he had been chosen to do the Lord's work. Unlike Tony Blair, he had no compunction about avowing his sense of divine mission, and with each victory his faith in "God's providence" deepened.

Cromwell's biographer Barry Coward thinks that the turning point came in July 1644 in Yorkshire, at the Battle of Marston Moor, where the Ironsides smashed royalist strength in the north of England. "Truly England and the Church of God hath had a great favour from the Lord," Cromwell enthused in a letter to his brother-in-law after the victory. "God made them as stubble to our swords."

The parliamentary press - for this was a conflict played out in print as well as on the battlefield - also saw Cromwell as an instrument of God. For the newspaper Perfect Diurnal, he was "one of the Saviours (as God hath miraculously manifested him to be) of this Israel". And from this point onwards, Cromwell's sense of mission never wavered. "Thus you see what the Lord hath wrought for us," he wrote ecstatically after another battle a year later. "Now can we give the glory to God, and desire all may do so, for it is all due unto Him!"

Yet there was another side to Cromwell's fervent religiosity. Though popular memory often casts him as the intolerant destroyer of church decorations, we ought to remember him as the champion of religious liberty. All "men that believe in the remission of sins through the blood of Christ", he once said, "are members of Jesus Christ and are to him as the apple of his eye". Naturally his idea of toleration only went so far: "popery and prelacy", which he associated with the corrupt Cavaliers, were definitely beyond the pale. But the fact remains that, by the standards of his day, he was exceptionally tolerant: during the Protectorate, there was far more freedom of conscience than under James I, Charles I or Charles II.

“I had rather that Mahometanism were permitted amongst us," Cromwell said in 1650, "than that one of God's children should be persecuted." This was an extraordinary thing for a 17th-century Protestant gentleman to say. No wonder he was regarded as "the darling of the sectaries [dissenters]". Yet when Charles I gave himself up to parliament's Scottish allies in May 1646, Cromwell was still a long way from the top of the political ladder. Like most of his comrades, he found it hard to imagine a settlement without the king. Within just a few months of the end of the war, the winners had fallen out among themselves.

Parliament and the Scots wanted a settlement that would disband the army, restore Charles to the throne and impose Presbyterian uniformity on the Church of England; but to the New Model Army, parliament's proposals were a sell-out. As so often, the soldiers had been made radical by the years of bloodshed: furious at the endless delays in getting their pay, they were outraged at the thought of having to endure yet another kind of religious authoritarianism. Cromwell, by this point their deputy commander, faced a historic choice: his Presbyterian allies in parliament or his "Independent" comrades in the army. He chose the army.

History can too often seem like the clash of Machiavellian personalities, so it is worth remembering that, like many other leaders before and since, Cromwell was essentially the prisoner of events. He seems to have been taken aback by the radicalism of his men - at one stage he retired from political life for a month with a psychosomatic illness - and only reluctantly left Westminster to join them. Torn between the social conservatism of a country gentleman and his impassioned commitment to the Independent cause, Cromwell tried to play the mediator. When the radicals in the army - the Levellers, later reinvented by the likes of Tony Benn as proto-socialists - met with their officers at Putney to discuss the way forward, Cromwell acted as ringmaster, hoping to find common ground. As so often, he fell back on religion when the debate got out of hand, suggesting at one point a break for prayer. "Perhaps God may unite us," he said, "and carry us both one way."

Then everything changed. On 11 November 1647, Charles escaped from his guards at Hampton Court and fled to the Isle of Wight. By the summer of 1648 the country was engulfed in a second civil war, this time with the Scots on the king's side. It was the decisive event in Cromwell's life. At Preston, in Lancashire, he smashed a royalist army twice the size of his own, strengthening his view that he was God's chosen instrument, and that the Lord wanted him to "call Charles Stuart, that man of blood, to an account for that blood he had shed, and mischief he had done".

The irony was that, far from being a repub­lican, Cromwell always believed that only a monarchical system would ensure stability - but the king's duplicity, he told a friend, left them with "no other way". In December 1648, Colonel Thomas Pride led his men in to parliament, arresting wavering MPs in what became known as Pride's Purge. Six weeks later, Charles was put on trial. Ten days after that, he was dead.

Even after the king's execution on 30 January 1649, Cromwell's position remained strikingly ambiguous. Although he was, in effect, head of the army, he was no dictator; in theory, power had passed to the new Council of State, of which he was only one member.

In any case, the revolution still looked decidedly shaky. In Ireland, Catholic rebels had reached a deal with the royalists, an alliance that reawakened many English Protestants' worst fears. As Christopher Hill puts it, Ireland had long seemed "an open back door to foreign invasion". Even now, Charles's nephew Prince Rupert was hovering off the Irish coast. Hungry for a quick military victory, the so-called Rump Parliament told Cromwell to solve the Irish problem for good.

What happened next is probably the most divisive incident in the long and unhappy history of Anglo-Irish relations. There is no doubt that, like most Englishmen of his generation, Cromwell loathed Irish Catholicism. Transfixed by the memory of the rebellion of 1641, he was determined to exact revenge. Yet as John Morrill, the dean of 17th-century scholarship, puts it, the Irish campaign has become a "legend rooted in half-truths". Would the massacres at Drogheda and Wexford in late 1649, where perhaps 7,000 people were killed, have happened in England? Almost certainly not; but, as Morrill notes, Cromwell was following "the laws of war as they had operated in Ireland for the previous century".

As usual, Cromwell justified himself in terms of religion: the massacres, he said, were "a righteous judgment of God upon these barbarous wretches, who have imbued their hands in so much innocent blood and . . . will tend to prevent the effusion of blood for the future. Which are the satisfactory grounds to such actions . . ."

More than a few historians have compared them to the bombings of Hiroshima and Naga­saki - to some observers, they are atrocities; to others, regrettably harsh measures that spared more bloodshed later on. Cromwell's more sweeping critics often forget that, in the next few months, he offered remarkably generous terms for surrender at towns such as Macroom, Kilkenny and Clonmel. At the very least he deserves to be judged by the standards of his own time rather than to be caricatured by the simple-minded products of ours. Like so many generals after him, from the Duke of Wellington to Dwight D Eisenhower, he returned to find that military success abroad had made him a star at home. By now his sense of divine providence was at its height. "You can scarce speak to Cromwell about anything," said a hostile pamphlet, "but he will lay his hand on his breast,

elevate his eyes and call God to record; he will weep, howl and repent even while he doth smite you under the fifth rib."

After he smashed the Scots again at Dunbar, he seemed to observers to be in some sort of frenzy, laughing like a madman while his eyes "sparkled with spirits".

Now more than ever, Cromwell was convinced that God had plucked him from obscurity to lead England into a golden age of Protestant virtue. And by April 1653, infuriated by the Rump Parliament's endless squabbling and religious intolerance, he had had enough. Perhaps his words should be etched above the doors to the Commons as a reminder to modern MPs not to get above themselves.

“Ye sordid prostitutes, have you not defiled this sacred place, and turned the Lord's temple into a den of thieves, by your immoral principles and wicked practices?" he shouted. "Ye are grown intolerably odious to the whole nation; you who were deputed by the people to get grievances redressed, are yourselves become the greatest grievance." And as his soldiers cleared the chamber, he said: "Take away that fool's bauble, the Mace . . . Depart, I say, and let us have done with you. In the name of God, go!"

As Lord Protector of England, Scotland and Ireland, Cromwell was now in an extraordinary position. Nobody in British history, perhaps not even a monarch, has ever held so much power. Despite the crude caricatures by his opponents, he was no dictator: three times in the next five years he called parliaments of one kind of another, striving to achieve a lasting constitutional settlement.

Even his critics noted that he still wore a cheap coat, "plain black clothes" and "grey worsted stockings". And though he gradually acquired the trappings of monarchy, he remained at heart the same anxious, driven, plain-speaking man, tortured by his own failings, craving signs of God's approval.

Perhaps the most revealing moment in his whole career came in 1657, when the Protectorate Parliament urged him to take the crown and thereby ensure a lasting settlement. A more ambitious or self-interested man would probably have accepted it. True, some of his fellow officers hated the idea, but King Oliver would have been strong enough to endure the pressure. Yet after six weeks of agonising - during which he was so sick with doubt that he missed meetings and even presented himself to visitors "half unready in his gown" - he turned it down. As so often, his sense of divine providence had been decisive. "I would not seek to set up that which Providence hath destroyed and laid in the dust," he explained, "and I would not build Jericho again."

The irony is that, in just a few years, Cromwell proved a far better head of state than almost any other incumbent in our history.

Absurdly, he is remembered today for "banning" Christmas - though it had nothing to do with him but had been instituted by parliament in the 1640s as an attempt to eliminate crypto-Catholic superstitions. By any sensible standard, however, the Protectorate was a great success. Given the bloodshed and turmoil that had gone before, it is easy to imagine Britain sliding into anarchy, repression or renewed civil war. After repeated harvest failures, and with food prices rising sharply, thousands starving on the streets and the press full of hysterical warnings about Ranters and radicals, there was a great risk of total social collapse. Yet Cromwell's achievement - a reflection of his political moderation, his modest temperament and his relatively tolerant religious vision - was to give Britain stability after years of chaos. Even the much-mocked Barebones Parliament, an assembly of hand-picked godly reformers, was much more moderate, efficient and effective than is often remembered.

Where Cromwell scores unexpectedly highly is in his foreign policy. Largely forgotten today, the first Anglo-Dutch war in the early 1650s was a watershed in British history, ending Holland's domination of international trade and marking the emergence of the British navy on the world stage. For Hill, Cromwell's administration was "the first in English history to have a world strategy". Until the 1650s, Britain had been a backwater; a decade later, with its security assured and its sea power rising inexorably, the transformation was "astonishing".

Cromwell died peacefully in his bed in September 1658, carried off by malaria, pneumonia and exhaustion in the middle of the greatest storm that anybody could remember. Within 18 months, the Protectorate had collapsed, the monarchy had been restored and Charles II was back in England.

Yet we often forget that Cromwell had the last laugh. In the decade after his death, as Charles II danced and dithered, even royalists sometimes wished the Protector was back in charge. "It is strange how everybody do now-a-days reflect upon Oliver and commend him, what brave things he did and made all the neighbour princes fear him," wrote Samuel Pepys in 1667. The Dutch ambassador told the king to his face that "Cromwell was a great man, who made himself feared by land and sea".

“His greatness at home," admitted the royalist Earl of Clarendon, "was but a shadow of the glory he had abroad. It was hard to discover which feared him most, France, Spain or the Low Countries, where his friendship was current at the value he put upon it."

In the long run, as Hill notes, the reigns of Charles II and James II were mere interludes: after the Glorious Revolution of 1688, when the Catholic James was kicked off the throne to make way for William of Orange, "the policies of the 1650s were picked up again". In the two centuries that followed, the things Cromwell had come to represent - the rule of parliament, the importance of commerce, the rise of sea power, tolerance of religious diversity and perhaps, above all, the moral, cultural and economic energy of the Protestant "middling sort" - came to define Britain itself.

To complacent modern eyes, much that we associate with Cromwell - his burning religiosity, his ruthlessness in battle, his instinctive patriotism, his sense of mission - can seem unsettling. Yet not only did he pave the way for the "great commoners" who ruled Britain in the next century, but he can be seen as a forerunner of the ordinary men who became presidents of the United States - a quasi-monarchical, self-consciously virtuous republic that was inspired directly by the Good Old Cause of the 1640s and 1650s. But the story that as a young man Cromwell almost fled to New England is probably a myth; for one thing, he believed that God had chosen England to be his "firstborn", his "delight among the nations".

For those who like their heroes to stay two-dimensional do-gooders, he probably seems a disturbingly abrasive figure. In many ways he remains a difficult man to love, but, unlike so many political leaders after him, he was a recognisably rounded, human figure, painfully aware of his own flaws. "A larger soul, I think, hath seldom dwelt in a house of clay than his was," wrote John Maidstone, steward of Cromwell's household, after his master's death. His words make a fitting epitaph for the greatest man in our history, warts and all.

Dominic Sandbrook's latest book is "State of Emergency: the Way We Were - Britain, 1970-1974", published by Allen Lane (£30)