Pakistan's General Pervez Musharraf said farewell to military colleagues on Tuesday as he prepared to become a civilian president ahead of January's general election.

Musharraf visited Joint Staff headquarters in Rawalpindi and the navy and air force headquarters in nearby Islamabad, a day before he steps down as army chief to fulfill one of the long-held demands of his political rivals and Western allies.

All main opposition parties have signed up for the January 8 parliamentary election, but former prime ministers Benazir Bhutto and Nawaz Sharif, both back in Pakistan after years of exile, have said they may still boycott the vote which is being organized under emergency rule.

Musharraf will be sworn in as a civilian president on Thursday, his spokesman said, after securing a second five-year term thanks to a new panel of friendly judges who validated his October 6 election victory.

The U.S. ally who seized power in a 1999 coup has seen his popularity plummet since March when he tried to fire the country's independent-minded top judge, triggering a campaign against him by lawyers and the opposition.

Many ordinary Pakistanis who initially welcomed the coup against Sharif have turned against the army chief as they struggle to cope with rising prices for food and fuel.

I'm happy he's quitting the army. During his rule we've seen prices go up and it has become difficult for poor people like us to live, said Babar Ali, 25, serving portions of guava from a barrow on a pavement in the city of Lahore.

I don't accept him as a president because he has made our lives so miserable, he said.

U.S. State Department spokesman Sean McCormack on Monday welcomed Musharraf's promise to take off his uniform, but told reporters in Washington Musharraf must lift the state of emergency he declared on November 3 before elections are held.

His main reason for imposing emergency rule was to clear out Supreme Court judges who were apparently about to rule in favor of challenges to his re-election, analysts say.

UNPOPULAR

Sharif and Bhutto are both demanding an end to the emergency and other steps they say are essential for a fair vote. They also want to see sacked judges reinstated.

Sharif told reporters Musharraf's departure from the army was not the issue as he was constitutionally bound to quit anyway.

The issue is those actions he took on November 3 have to be reversed if we are to hold free and fair elections, he said.

An Interior Ministry spokesman said 5,748 people detained under the emergency had been freed and only 37 were still in detention, among them prominent lawyer Aitzaz Ahsan. The judges who defied Musharraf are also under house arrest.

Pakistani stocks ended slightly higher as investors kept a wary eye on politics, while ratings agency Standard & Poor's said Pakistan's credit ratings could be eroded by more instability or regression into an ineffectual administration under an elected government.

Musharraf's unpopularity is likely to hit his ruling Pakistan Muslim League party in the election. The party was drawn from the rump of Sharif's old party and the former prime minister's return home could draw support back to him.

The most likely outcome is a hung parliament with no party winning a clear majority, analysts say. Musharraf would then need the help of religious parties or one or other of his old rivals.

A hostile parliament may try to impeach Musharraf over his maneuvers to secure another term in office, which opponents say violated the constitution.

Musharraf will be replaced as army commander by his former intelligence chief, General Ashfaq Kayani. He is well regarded by Western counterparts and also worked with Bhutto after she first become prime minister in the late 1980s.

He takes over a military suffering from low morale and embroiled in internal security operations against militants in the northwest who repeatedly strike security forces with suicide bombers.

(Additional reporting by Augustine Anthony, Kamran Haider in LAHORE; Writing by Robert Birsel; Editing by Rosalind Russell)