Musharraf's resignation comes nearly nine years after the key U.S. ally in the war against terror took power in a coup. A career army officer, Musharraf narrowly survived several assassination attempts.
"I hope the nation and the people will forgive my mistakes," Musharraf, 65, said in an hour-long televised address devoted to defending his record and refuting criticisms.
Speculation Musharraf would resign had mounted since the coalition government, led by the party of assassinated former Prime Minister Benazir Bhutto, said this month it planned to impeach him.
"Whether I win or lose, the nation will lose," Musharraf said of the impeachment process. "The honor and dignity of the country will be affected and in my view, the honor of the office of president will also be affected."
Coalition officials had said earlier Musharraf had sought immunity from prosecution, but he said in his speech he was asking for nothing.
One of the main coalition parties, that of former prime minister Nawaz Sharif, whom Musharraf ousted in 1999, has been insisting he face trial for treason. Bhutto's party has said Parliament should decide.
Many Pakistanis blame the rising militant violence in their country on Musharraf's alliance with the U.S. His reputation suffered blows last year when he ousted dozens of judges and imposed emergency rule. His rivals won parliamentary elections in February and have since sought his ouster, announcing impeachment plans earlier this month.
Musharraf, who has been largely sidelined since his rivals came to power, had resisted the mounting calls to quit, even 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.
The United States had said earlier Pakistan's leadership was a Pakistani issue.
"We will continue to work with the Pakistani government and political leaders, and urge them to redouble their focus on Pakistan's future and its most urgent needs, including stemming the growth of extremism," Secretary of State Condoleezza Rice said Monday. "[He] has been a friend to the United States and one of the world's most committed partners in the war against terrorism and extremism."
It was not clear who the next president would be. According to the constitution, the chairman of the Senate will become acting president until a new one is elected within 30 days.
There has been speculation that both Sharif and Asif Ali Zardari, the leaders of the two main parties are interested in the role.
The army, which has ruled for more than half the country's 61-year history, has publicly kept out of the controversy over its old boss, and no protests over Musharraf's decision were expected.
Pakistan's old rival India reacted cautiously, saying it was an internal Pakistani matter. "India will continue to have an amicable relation with Pakistan in the days to come," Foreign Minister Pranab Mukherjee told reporters.
Television footage showed groups of people dancing in the streets and handing out sweets in several towns across Pakistan.
"Thank God he's resigned. The country will do much better now," Mohammad Ilyas told Reuters in Karachi.
In the northwestern city of Peshawar, a crowd of people danced to drum beats and hugged each other.
"It is very pleasing to know that Musharraf is no more," Mohammed Saeed, a shopkeeper, told the Associated Press.
Pakistan's stock market and currency both rose strongly on hopes that the country was bound for political stability.
Musharraf ended his final address as president with the words: "May God protect Pakistan, may God protect you all. Long live Pakistan forever."