General Pervez Musharraf finally quit as Pakistan army chief on Wednesday, trading the post for a second five-year term as president and fulfilling a promise many Pakistanis doubted he would keep.

He passed the baton of command to his hand-picked successor, General Ashfaq Kayani, at a ceremony at army headquarters in Rawalpindi.

Musharraf, who took power in a 1999 coup, is to be sworn in as civilian president on Thursday, having relinquished his position in the one institution that guaranteed his power.

The system continues, people come and go, everyone has to go, every good thing comes to an end, everything is mortal, a tearful Musharraf told top brass and government leaders at the change-of-command ceremony.

The opposition parties of former prime ministers Benazir Bhutto and Nawaz Sharif, who are both mulling their participation in a January 8 general election, welcomed Musharraf's resignation.

It is a pleasant moment in the history of Pakistan. Now our army will get a full-time general as its leader, Bhutto told reporters in Karachi.

Musharraf's power and influence are bound to be diminished. The question is by how much.

Naturally, the support of the army, that's what has been vital, said a former army commander, Mirza Aslam Beg, who declined to take power when President Mohammad Zia-ul-Haq was killed in a 1988 plane crash.

Beg said he expected significant changes, beginning with more aggressive opposition demands to end emergency rule.

Musharraf is due to address the nation on Thursday after being sworn in, and he could use the occasion to end the emergency.

Pakistani stock investors welcomed Musharraf's resignation as a step towards stability. The index ended 0.63 percent higher, boosted by talk that the emergency was about to be lifted.

Government officials said Musharraf's resignation would have no impact on Pakistan's efforts to combat terrorism.

NEEDS SUPPORT

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 neighboring Afghanistan.

Musharraf had assured Washington 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 might 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, whom Musharraf ousted in 1999, 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 maneuvers 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 skepticism 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, Kayani was 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 a prime minister would go against Musharraf unless they were sure the army had come to regard him as a liability.

That might require large-scale agitation in the streets or a withdrawal of support from Washington.

British Prime Minister Gordon Brown welcomed Musharraf's resignation as an important step towards the restoration of constitutional order.

(Writing by Simon Cameron-Moore; editing by Robert Birsel and Roger Crabb)