It’s just over a month since the capture and death of colonel Gaddafi completed the liberation of Libya. It was accompanied by much hand-wringing over the dictator’s brutal and undignified end, to the effect that this was a bad omen for the rule of law in Libya and that the country’s new leaders were culpable for not having ensured that he was kept alive and forwarded to the international criminal court in The Hague.

Well, maybe so, although the early signs from Libya’s transition look pretty good. But the real impact of Gaddafi’s fate has been outside of Libya. For the rest of the middle east it seems there are real advantages in killing a dictator from time to time, as Voltaire would have said, pour encourager les autres.

While Libya was still deadlocked, it looked as if the Arab Spring was faltering. But now there is a new momentum: in Syria in particular the opposition has clearly taken fresh inspiration, hoping that their struggle against Bashar al-Assad will eventually win the same international support that the anti-Gaddafi forces received. And the demonstrators in Cairo this week have told Field Marshal Mohamed Hussein Tantawi that if he tries to emulate Assad, he will share the fate of Gaddafi.

Now comes a new domino, one that has taken a long time to fall.

President Ali Abdullah Saleh of Yemen yesterday signed an agreement to relinquish power to a government of national unity that will prepare for early elections, in return for which he has been promised immunity from prosecution.

The agreement dates back to April, when Saleh promised to sign but later backed out. Since then he has been wounded in a rocket attack on the presidential compound, spent time in Saudi Arabia for treatment, returned to Yemen but again stalled on negotiations, and now finally been brought into line by international (mostly Saudi) pressure. During this time protests and sporadic violence have continued.

Initial reactions suggest that the protesters are not happy about the immunity for Saleh or the continued influence that his circle might have in the interim government. But both sides should know by now that immunity deals are frequently unwound when new governments are established, and Saleh, who plans to go to the US for further treatment, would be well advised to make his absence permanent.

Saudi Arabia and the Gulf states have played a different game in Yemen to that in Syria. Assad was always an outsider, and while (from the Saudi point of view) undermining any autocrat is risky they had fewer qualms about cutting him loose. Saleh, however, although a Shi’a ruling a predominantly Sunni nation, had worked hard to mend fences with the Saudis, so the aim has been to manage the process in such a way as to avoid revolutionary change while maintaining credit with both sides.

It’s in the nature of revolutions, of course, to resist “management”, and it’s by no means certain that the Yemeni agreement will ever be fully implemented. Having made the one big gain, the opposition may press for a more complete and immediate purge of the regime, and if they do they will probably get it. Saleh’s loyalists may have risked their lives to preserve his power; few will do so just to defend a gradual transition.

So despite yesterday’s achievement there will be some worried faces in Saudi Arabia and among the Gulf monarchies. They know they are not immune; Bahrain just this week has had to acknowledge “excesses” in its own suppression of protests. The flames of revolution are flickering ever closer, and rulers are desperately searching for the right mix of concessions and force to keep them at bay.

If they get it wrong, they will end up like Saleh. If they get it badly wrong, they will end up like Gaddafi.