Pakistani President Pervez Musharraf announced his resignation Monday, ending a nearly nine-year tenure that opponents said was hampering the country's shaky return to democracy. An emotional Musharraf said he wanted to spare Pakistan a dangerous power struggle with opponents vowing to impeach him. He said he was satisfied that all he had done "was for the people and for the country." "I hope the nation and the people will forgive my mistakes," Musharraf said in a televised address, much of which was devoted to defending his record. His political exit robs the West of a stalwart ally who echoed its concern about how Islamic militancy is destabilizing Afghanistan and Pakistan, where al-Qaida and the Taliban have regained strength. However, his influence has faded since he stepped down as army chief last year. Pakistan's stock market and currency both rose strongly on hopes that the country was bound for political stability. In his hour-long address, Musharraf said he would turn in his resignation to the National Assembly speaker Monday. It was not immediately clear whether it would take effect the same day. Mohammedmian Soomro, the chairman of the upper house of parliament, was poised to take over in the interim. It remains an open question whom parliament will elect to succeed Musharraf, largely because the ruling coalition has vowed to strip the presidency of much of its power. There is speculation that both Nawaz Sharif and Asif Ali Zardari, the leaders of the two main parties, are interested in the role. However, neither has openly said so. It was also unclear whether Musharraf would be able to stay in Pakistan. Foreign Minister Shah Mahmood Qureshi said leaders of the ruling coalition would discuss later Monday whether to prosecute Musharraf in court on the impeachment charges. Most of his political foes put those issues on the back-burner and got on with celebrating. "It is a victory of democratic forces," Information Minister Sherry Rehman said. "Today the shadow of dictatorship, that has prevailed for long over this country, that chapter has been closed." Television footage showed groups of people celebrating in the streets in several towns across Pakistan, some of them firing automatic weapons into the sky. "It is very pleasing to know that Musharraf is no more," said Mohammed Saeed, a shopkeeper among a crowd of people jigging to drum beats and hugging each other at an intersection in the northwestern city of Peshawar. "He even tried to deceive the nation in his last address. He was boasting about economic progress when life for people like us has become a hell," he said, because of economic problems that include runaway inflation. Musharraf dominated Pakistan for years after seizing power in a 1999 military coup, making the country a key strategic ally of the US by supporting the war on terror. But his popularity at home sank over the years. Many Pakistanis blame the rising militant violence in their country on Musharraf's use of the army against militants nested in the northwest. His reputation suffered fatal blows in 2007 when he ousted dozens of judges and imposed emergency rule. His rivals won February parliamentary elections and have since sought his ouster, announcing impeachment plans earlier this month. Musharraf, who has been largely sidelined since his rivals came to power, finally yielded after the coalition finalized impeachment charges against him and threatened to send a motion to Parliament later this week. The charges were expected to include violating the constitution and gross misconduct, likely in connection with the ouster of the judges and the declaration of emergency rule. A defiant Musharraf, seated in an office between two national flags, listed the many problems facing Pakistan, including its sinking economy and a chronic power shortage. He said his opponents were wrong to blame him for the mounting difficulties and suggested they were going after him to mask their own failings. "I pray the government stops this downward slide and takes the country out of this crisis," he said. Allies and rivals of the president said talks had been under way to get him to step down by possibly granting him legal immunity from future prosecution. The second biggest party in the government has said he should be tried for treason, which carries a maximum punishment of death. Qureshi would not say whether Musharraf might be granted a "safe exit" - speculation has focused on whether he might go into exile in Saudi Arabia or Turkey - or dragged through the courts. "That is a decision that has to be taken by the democratic leadership," Qureshi, who is from the main ruling Pakistan People's Party, told Dawn News television. The leaders would assess the speech and the political situation, he said. A US Embassy spokesman declined to comment after Musharraf's speech, referring calls to Washington. US Secretary of State Condoleezza Rice said Sunday that while Musharraf had been a "good ally," Washington was supportive of the new government and Musharraf's future was an internal issue. "Pakistan and the United States have a joint interest in fighting terror," Rice said on Fox News television. "That's what we're concentrating on, that and helping Pakistan to sustain its economy, to build its schools, its health. We have a broad Pakistan policy."