Immediately after being elected as Pakistan's prime minister on Monday, Yousaf Raza Gilani made good on a pledge to free judges who had been detained by President Pervez Musharraf.

Among the judges released by Gilani was Chief Justice Iftikhar Mohammed Chaudhry, who had been under house arrest since November after opposing Musharraf.

In his first public appearance since being placed under house arrest, Chaudhry emerged from the balcony of his home, which was surrounded by dozens of his supporters, and offered his thanks.

A longtime loyalist to Pakistan's slain opposition leader Benazir Bhutto, Gilani was elected by a strong margin of 264-42 in the National Assembly vote Monday. He immediately shook hands with Bhutto's son Bilawal Bhutto Zardari.

"Democracy has been revived due to the sacrifice of Benazir Bhutto," Gilani said, adding that one of his first acts would be to demand a probe into Bhutto's death.

"We didn't get here out of charity. This moment came because of continued struggle and martyrdom."

Gilani had vowed to fight for the release of judges that have been locked up since before Bhutto's assassination.

He will form a government that will be dominated by foes of Musharraf -- whose leadership has been under fire since he locked up judges that challenged him, cracked down on press freedoms and put the country under military rule.

Gilani and his allies have vowed to slash Musharraf's powers and conduct a review of his counterterrorism policies.

Pakistan, and by extension Gilani's new government, faces challenges that include mounting economic problems such as skyrocketing inflation, power shortages and slumping foreign investment.

Harlan Ullman, a military expert and retired U.S. Naval Commander who just returned from Pakistan, told CTV's Canada AM he met with key players during his visit and sees some hope that Pakistan's situation will improve.

"We are a bomb or a bullet away from disaster. Pakistan is a very dangerous place but for the time being I think there are grounds for some degree of optimism as this new government takes shape," he said.

Ullman said it is likely Gilani's election will also result in improved press freedoms.

Athar Minallah, a lawyer close to Chaudhry, told The Associated Press he was looking forward to returning to work.

"He's in extremely high spirits and is extremely looking forward to taking up his office as the chief justice of Pakistan," Minallah said after emerging from Chaudhry's home. "This is the dawn of a new era. It's the end of dictatorship in this country."

Gilani will be sworn in by Musharraf on Tuesday.