In the capital, police fired tear gas at protesters outside the residence of Iftikhar Mohammed Chaudhry, the chief justice whom Musharraf suspended exactly one year earlier and accused of conspiring against him.
Asif Ali Zardari, the widower of slain opposition leader Benazir Bhutto, and Nawaz Sharif, whose government was ousted in Musharraf's 1999 coup, announced their pact after talks at a resort town in the foothills of the Himalayas.
"The coalition partners are ready to form the government," Sharif said at a news conference, reading from a joint statement.
Zardari, seated alongside, said his party had signed the agreement in honor of Bhutto, who was assassinated in a suicide bombing on Dec. 27, and her desire to put back Pakistan back on "the road to democracy."
Bhutto's Pakistan People's Party has won 120 seats in the new 342-seat National Assembly, following by Sharif's Pakistan Muslim League-N with 90. The former ruling party aligned with Musharraf got just 51.
The two largest parties, both moderate and secular, have vowed to form a broad-based government, raising Western hopes of stability and renewed commitment to fighting al Qaeda and Taliban militants.
However, they are devoting most of their energy to cutting back Musharraf's sweeping powers a course the former military strongman seems unlikely to accept meekly.
Zardari and Sharif declared a breakthrough on two key issues: the makeup of the coalition and the future of the judiciary.
Sharif said his party would be part of a federal coalition led by the People's Party, which is expected to name its candidate for prime minister this week.
In return, Zardari agreed that the new parliament would pass a resolution within 30 days of its formation to reinstate dozens of judges fired by Musharraf last year.
The leaders agreed that the judiciary would be restored "as it was on Nov. 2," suggesting that Chaudhry would return to the helm of the Supreme Court.
But Zardari muddied the issue by saying that the current judges, who stepped up after the purge, would not be "disturbed."
"I think we'll have to take a ... stance on this whereby we have a collective wisdom and accommodate everybody," Zardari said.
Musharraf first suspended Chaudhry on March 9, 2007, eroding his popularity and triggering lawyers' protests that grew into a powerful pro-democracy movement.
The Supreme Court reinstated Chaudhry in July and was poised to rule on the disputed legality of Musharraf's re-election as president when he declared emergency rule on Nov. 3, drawing loud criticism at home and abroad.
On Sunday, lawyers announced a week of fresh protests and urged the new parliament to get the judges' restored.
About 600 demonstrators marched on the residence in Islamabad where Chaudhry has been under house arrest for four months, chanting "Go Musharraf go" and "We want freedom."
Police in riot gear fired tear gas after some protesters tried to cut through barbed wire at concrete barricades that block the entrance to the house.
Several thousand people, including labor union members and journalists, gathered peacefully in the southern city of Karachi also demanding that Musharraf step down.
"This is the verdict of the people of Pakistan," read one banner, referring to the outcome of the elections.
Musharraf has accused Chaudhry of corruption and conspiring against his effort to guide Pakistan back to democracy and some commentators predict that he will quit if the judge returns.
Musharraf has said he will convene parliament shortly and on Saturday appealed to the election winners to turn to the business of governance in a country facing growing economic problems as well as Islamic extremism.
"Put the politics on the back burner and run the government," Musharraf said.