It has been a messy transition for a leader of a nuclear-armed country that is key to the U.S. campaign against al Qaeda and its strategy in neighbouring Afghanistan.
Musharraf had assured the United States that everything would be done according to the constitution, which obliged him to quit the army before the end of the year.
The trouble was he had to suspend the constitution, declare emergency powers and purge the Supreme Court to make it happen.
Otherwise the judges could have annulled his October 6 re-election by the outgoing parliament on the grounds that he contested it while still a serving officer.
How long he will keep the presidency will depend on the parliament that emerges from the election, particularly as Bhutto and Sharif have been allowed back to lead their parties.
Musharraf will need support in what analysts expect to be a hung parliament. He could face impeachment over manoeuvres to stay in power which rivals say violated the constitution.
Ordinary Pakistanis welcomed Musharraf's departure from the army, and some said it was time he left politics altogether.
"I think his role in Pakistani politics is ending now, and it's only a matter of time before he will be kicked out by the people, or by the army itself," said Abdul Aziz Khan, a retired banker in Karachi.
Musharraf's trump card remains the military, which backed his use of emergency powers. Having run the country for more than half the 60 years since its creation in 1947, the military has an ingrained scepticism when it comes to civilian leaders.
The poker-faced, chain-smoking Kayani is seen as loyal to Musharraf. As director-general of the Inter-Services Intelligence, Pakistan's main spy agency, the post he held prior to being designated Musharraf's successor last month, Kayani became well regarded by U.S. counterparts.
Musharraf has said that he expects Pakistan to be governed by a troika, made up of himself, Kayani and the new prime minister.
In those circumstances, it is unlikely that a prime minister would go against Musharraf unless they were sure that the army had come to regard him as a liability.
That might take large-scale agitation in the streets or a withdrawal of support from Washington, Pakistan's main source of aid and arms, analysts say.

















