The party's victory was paved by a reconciliation between Anwar and 92-year-old Mahathir Mohamad, who ruled Malaysia with an iron fist from 1981 to 2003, and came out of retirement to lead the Alliance of Hope to victory.
Anwar waved to reporters as he was whisked from a hospital Wednesday where he was recovering from shoulder surgery.
The second 'sodomy ' case against Anwar Ibrahim began in 2008.
"After the votes were counted and PKR won the most (parliament) seats, Wan Azizah was suggested by the King (to become the prime minister)", he said.
The 70-year-old was greeted by the new Malaysian prime minster and former political-enemy-turned-ally Mahathir Mohamad upon arrival at the palace, and was accompanied by Selangor Menteri Besar Azmin Ali and deputy prime minister Wan Azizah Wan Ismail, who is also Anwar's wife. Rising public anger at a massive government corruption scandal under now ousted prime minister Najib Razak, who stands accused of presiding over the plundering of the state investment fund 1MDB, boosted support for the opposition.
Anwar said, stressing that the Agong acted the moment he received all the details of the election results.
Last week, "we freed Malaysia from BN, today we freed Anwar Ibrahim from prison", PKR Youth chief Nik Nazmi tells cheering crowd.
Anwar's prison sentence ends on June 8, but without a royal pardon he would be barred from politics for five years.
"But naturally, it would take weeks or months...from Harvard, Stamford and other universities because I think I have a small contribution to make...to show that the voice of reason and moderation in Islam is paramount and Muslim can be counted upon to ensure freedom and justice", he said.
Anwar, however, was again jailed for sodomy in 2015, this time during the premiership of Najib Razak.
Upon his release in 2004, Anwar galvanised the "Reformasi" movement against the Barisan Nasional coalition that Mahathir was then leading - and that Anwar himself had helped start before going to jail. He reiterated his full support for Mahathir's leadership and said their political feud has always been buried.
Unity between Mr Mahathir and Mr Anwar is necessary for the government to move quickly to implement election promises.
Anwar, popularly known as "Pak Syeikh" in his glorious past as Deputy Prime Minister, today underscored two important points, giving support to Dr Mahathir for the reform agenda, which is the agenda of young people in the country.
His freedom is expected to ease fears of a growing rift within the newly formed coalition government, after differences erupted between supporters of Mahathir and Anwar over cabinet positions and Anwar's role in the party. In 2000 he was convicted of sodomy and given an additional nine-year jail term.
He maintains his innocence, and says on both occasions Mahathir and Najib used trumped up charges against him to keep him out of politics.