"After long speculation and consultations with my associates I decided to submit my resignation to the national assembly today," Musharraf said on national TV.
He said he was resigning to prevent the country from plunging into instability.
"I hand over my future to the people," he said. "It's possible I might have made mistakes," he admitted, adding that, "my intentions were true."
Musharraf's decision marks the end of a bitter confrontation between him and the ruling coalition government that has been pushing for his resignation since its victory in the February 18 elections.
It is not clear yet whether he will be given immunity while he stays in Pakistan.
The ruling coalition, including the party of Nawaz Sharif, whose government was ousted in the bloodless 1999 military coup that brought Musharraf to power, and the Pakistan People's Party of former prime minister Benazir Bhutto, assassinated in December 2007, had asked him to quit to avoid impeachment.
On Sunday, a committee of the ruling coalition finalized a list of impeachment charges against Musharraf, including violation of the Constitution, suppression of democracy, and gross misconduct.
Musharraf said the country would lose if the impeachment proceedings were launched.
"Not a single charge can be proved against me," he said, adding however that "this is not the time for individual bravado."
Moscow said it hopes that Musharraf's resignation will not worsen the political situation in the country.
"Russia hopes that the resignation of Pakistan's President Pervez Musharraf will not have a negative impact on the domestic political stability of this large Asian country," Foreign Ministry spokesman Andrei Nesterenko said.