There are few things as exhilarating as a revolution, and few things as
frightening, writes John Simpson in Cairo.

A square, an angry crowd, banners, the bitter smell of burning, the grinding noise of manoeuvring tanks, blood: this time it's Cairo, but for the last three decades we have seen similar images from a range of autocracies under threat, from the Shah's Tehran, Deng Xiaoping's Beijing and Ceausescu's Bucharest to the uprisings of the last couple of years in Iran, Tunisia, and now Egypt.

Some of these revolutions failed. An autocrat who has the support of his army and his secret police, and whose nerve does not crack, can often restore order eventually.

InEgypt, President Mubarak has so far kept his nerve, and is winning the test of will with the demonstrators and with President Obama: up to a point. But the remarkable courage of the demonstrators has succeeded in forcing him aside: they just haven't managed to get him to go right now.

With an old man's stubbornness and pride, President Mubarak is determined to have the last word; he won't simply pack up and leave immediately. And the demonstrators in Tahrir Square, having done everything they possibly could to dislodge him, are finding it impossible to exert the last twist of pressure which would drive him out of his palace at once.

In an interview with the BBC Arabic Service, the prime minister, Ahmed Shafiq, has promised that there will be no action to force the demonstrators out of Tahrir Square. The government clearly believes the demonstrators will eventually drift away, and life will at last return to something like normal. It has been a hugely expensive business. One bank here estimates that the troubles have cost £190 million a day in lost revenue: over the nine days of turmoil, that represents more than the $1.5 billion which Egypt receives from the United States each year in military aid.

One lesson of the Cairo uprising is that when autocrats keep their nerve, they stand a better chance of getting away with it. The demonstrations in Tehran in June 2009 after President Ahmadinejad's dubious re-election eventually faded.

The Tiananmen Square killings cost China heavily in terms of reputation, trade and politics for some years, but the Communist Party is still in power, and still refuses to call what happened in June 1989 a massacre.

Last month President Ben Ali of Tunisia, always a mildly ludicrous dictator, realised the game was up directly the crowds came onto the streets. He gathered his most easily convertible assets, ordered his getaway plane, and headed off into a wealthy but probably not untroubled exile.

Muhammed Hosni Mubarak, by contrast, is a sticker. He has the military virtues of firmness and personal courage: when his friend and boss, President Anwar al-Sadat, was shot dead by Islamic army officers at a parade in 1981, Mubarak was one of the few men there who did not flinch.

His immediate instinct, when the example of Tunisia galvanised the middle class protesters of Cairo to take over Tahrir Square, was to send in the tanks and riot police. He gave orders to fire the buck-shot and live rounds which killed dozens upon dozens of people in Cairo, Alexandria and elsewhere.

It should have been enough to clear the Square, and all the other squares around the country. But the people who had come out to demand Mr Mubarak's resignation proved to be as stubborn as he was. They knew this would be their one chance of forcing political change, and they were not willing to let it go. Their will proved stronger than his.

He immediately fell back on compromise: he hadn't, he said plaintively, been planning to seek re-election in September anyway; his son would not be a candidate either; there would be an inquiry into the shootings; the much-hated parliament, recently elected, would be suspended. There was only one concession left to make after that: that he should step down immediately. So when he spoke to Christiane Amanpour of ABC News on Thursday, he confided to her that he was sick and tired of being President.

It still wasn't enough.

All this reminded me strongly of being in Tehran during the year-long revolution which culminated in the Shah's flight in January 1979. He too felt he had to stay, but he could never keep to one opinion for long.

Sometimes he gave his soldiers orders to open fire on the crowds, sometimes he offered concessions which were never enough to buy peace. In the end his worsening cancer and his disillusion got the better of him. He travelled the world for a while, shunned by countries which had once been only too happy to do business with him and take his money. President Sadat of Egypt, with the support and advice of the then-vice president, Hosni Mubarak, took him in for a while. Does Mr Mubarak think about that time now?

Those of us who remember Tiananmen Square were immediately seduced by the comparison with Tahrir Square. Most of the ingredients then were here now: the surprising courage of the enthusiasts for democracy, the demands they made, the tanks, the long stand-off.

But there have been subtle differences from Tiananmen Square, 22 years ago. The students had a leadership, naive and politically inexperienced perhaps, but clear-cut. By contrast the mostly middle-class people who have been occupying Tahrir Square have no real leaders.

Mohammed elBaradei, though well respected for his work with the International Atomic Energy Authority, is essentially a backroom boy, a civil servant rather than a politician.

He is treated with respect when he comes into Tahrir Square, but he is no leader of men. His speeches are quiet and halting, and the applause is muted. After he has finished, the next person to call for President Mubarak's immediate resignation gets a roar of approval, as though the crowd has just been waiting to let loose a bit of emotion.

The soldiers at Tiananmen Square on and off during the weeks of the demonstration were mostly sullen, unhappy at the position they found themselves, unwilling to take on the students but enraged at the way some of the wilder spirits in the crowd goaded them. In Tahrir Square the soldiers have undergone a clear conversion: they were sent in to frighten the crowd, but they later became victims of a kind of reverse Stockholm Syndrome, sympathising with them and preventing the pro-Mubarak groups from infiltrating the Square.

It is these groups which form the biggest difference from Tiananmen Square.

The working-class people of Beijing, as sick of Marxism-Leninism as the students, supported them wholeheartedly, and on the night of the massacre went on the rampage throughout Beijing and other cities, burning and looting government property and killing any policeman they came across.

Here, the gangs of pro-Mubarak supporters are angry with the demonstrators, whose actions have closed the shops and stopped the flow of wages and state benefits. The Mubarak loyalists wear no particular badges, and they carry Egyptian flags just as the demonstrators do. But you can recognise them instantly. They come from the slums, their clothes are cheaper and sometimes dirtier, and they are a great deal more aggressive.

Whether they are really paid by the government, as the demonstrators believe, is not proven. But they are certainly given transport from the drab, outlying suburbs, and they come in big groups. The similarity here is not with Tiananmen Square: it is with the square outside the old Communist Party headquarters in Bucharest in 1990. Ceausescu had fallen and been executed, and his supposedly democratic successor, President Ion Iliescu, had scarcely changed things. They demonstrated for greater freedom, and he shipped in gangs of miners from the provinces to attack them.

Watching the blood flowing from the heads and faces of demonstrators here, listening to the sound of the iron bars on their backs and shoulders, I have been reminded many times of Bucharest.

And, like Bucharest, this is difficult to report close up. Tiananmen Square, where the authorities were paralysed until the last couple of days before the massacre, was easy by comparison. Here, it takes a real effort of will to walk down into Tahrir Square, through the angry cordons of Mubarak supporters, to see for yourself what is happening. A television camera makes you an immediate target; so does a Western appearance and an air of foreignness. Egyptian state television has been telling people that Israeli agents are ranging round, posing as foreign journalists.

Vice-President Omar Suleiman, who has become the government's visible front-man (presumably because it is assumed that that the sight of Mr Mubarak will inflame television audiences even further), has assured the country that while the original demonstrators were thoroughly justified, they have been infiltrated by foreigners who have turned the protest into something darker and more evil.

As a result, being a foreigner in the streets of Cairo, and especially a foreign journalist, can be distinctly unhealthy. At the barricades manned by vigilantes every 30 yards or so along the roads and side-streets of the city centre, the scope for being taken out of your vehicle and beaten is pretty considerable. "You have camera? Cameras no good," shouted a drunk armed with a baseball bat through our car window at around midnight, the spit spraying across our faces.

Others demanded our passports, handing them round for inspection by the crowd. In the first half of the week the vigilantes were friendly, waving foreigners on when they saw them; the original purpose of the checkpoints was to stop potential looters, after the police had been withdrawn from the streets.

Now the vigilantes are looking for foreigners with television cameras. In most parts of the globe I find being recognised from BBC World News a big professional advantage. Here in Cairo, where it happens quite often, I have come to dread it.

There are few things as exhilarating as a revolution, and few things as frightening. For a brief moment people you have never previously met become your brothers, ready to lay down their lives for you; and then, in the next street, you can find yourself surrounded by a violent crowd which is fully prepared to beat you to death because you are different from them.

After a career which has taken in 14 revolutions, successful and failed, I find that this one has more of these paradoxes, in a fiercer form, than any others I have witnessed.

John Simpson's daily reports from Cairo can be seen on the BBC's news programmes and on The News Channel