Malaysia's jailed opposition icon Anwar Ibrahim was granted a full pardon and freed Wednesday, setting the scene for a revival of his political career after the long-time ruling coalition's landslide election loss last week.

The pardon enables the 70-year-old to run for office immediately and -- once securing a seat in parliament -- to take over the premiership from 92-year-old former nemesis-turned-ally Mahathir Mohamad.

According to a palace statement, King Muhammad V, upon the advice of the Pardon Board, decreed that Anwar be granted a full pardon and released immediately.

Anwar, who had been incarcerated for over three years for a sodomy conviction, walked out a free man from the hospital in Kuala Lumpur where he had been admitted for persistent back pain. He was scheduled to speak at a rally later in the day.

In his maiden press conference from his house, Anwar who accused former Prime Minister Najib Abdul Razak as being the mastermind behind his 2015 conviction, said the application for pardon was made because "there was a miscarriage of justice."

"We appealed because there was clear conspiracy to condemn me and assassinate my political character," he said.

Ironically, his release was made possible by Mahathir, the very man who as prime minister two decades ago upended Anwar's once-surging political career.

"Previously (people) said I jailed him, so now I freed him," Mahathir told reporters.

Mahathir attended the Pardon Board meeting at the National Palace earlier. He greeted Anwar there when the latter arrived to have an audience with the King Muhammad V after his pardon was confirmed.

In May 9 general election, the Mahathir-led, four-party opposition Alliance of Hope staged a historic upset against the once-mighty National Front coalition, which had ruled the country continuously since independence in 1957.

Before the poll, the alliance, which includes Anwar's People's Justice Party, pledged to seek a royal pardon for Anwar within 100 days of taking office if it won.

Even without the pardon, Anwar was still expected to be freed on June 8 for good behavior after serving two-thirds of his five-year sentence. But even then, Anwar would have been barred from running for office for five years. With the pardon, he can run immediately.

In January, the alliance made a pact that if it won the election, Mahathir would only warm the prime minister's seat while efforts were made to secure a pardon for Anwar.

But before Anwar can become prime minister, he needs to secure a seat in parliament by winning a by-election.

Anwar indicated that he is in no hurry to assume any position in the government, saying he wants to spend time with his family and hit the lecture circuit after receiving numerous invitations from various universities abroad.

He said he supports the government under Mahathir and his wife Wan Azizah Wan Ismail, who is the deputy prime minister-designate, and told Mahathir this when the latter visited him at hospital recently after the poll.

"I said, 'Look, it's better that you and Azizah and the team continue.' I said I have to travel quite a bit. I have given commitment to a few speaking engagements and I need time and space, and Tun has welcomed the decision. I don't need to serve in the Cabinet for now," Anwar told reporters from his house on the outskirts of Kuala Lumpur.

Mahathir himself has indicated he will stay on for a year or two only before giving up the reins to Anwar.

Anwar was once Mahathir's deputy, his heir-apparent who enjoyed tremendous power, when he was unceremoniously axed in 1998 and subsequently jailed for six years over his first sodomy and corruption charges.

Anwar, who claimed the charges were orchestrated to stave off a challenge against Mahathir's leadership, responded by rallying the people who took to the streets calling for Mahathir's ouster and for reform.

But now he insists it is all water under the bridge.

"It's a long time already. Why do we want to harp on this...I have forgiven him and he has proven his mettle. He has made sacrifices. He was maligned by media. It's like deja vu...He has now supported the reform agenda. He has facilitated my release. Why should I harbor any malice towards him?" Anwar told reporters.

The first sodomy conviction was overturned in 2004, resulting in Anwar's release from prison, and he then led the opposition to its best-ever showing in the 2008 general election.

But after the opposition broke the ruling coalition's stranglehold on two-thirds of the seats in parliament, Anwar found himself back in court on a second sodomy charge.

Less than a decade later, the latest chapter in Anwar's tortured and tumultuous career began to play out.

Despite the bad blood between them, Mahathir and Anwar turned Malaysian politics on its head by reconciling in 2016 and uniting in a bid to unseat Najib.

Mahathir has accused Najib of rampant corruption over various scandals involving 1Malaysia Development Berhad, a government investment fund that has lost billions of dollars in suspicious circumstances.

Before losing power in the latest election, Najib succeeded in thwarting a government investigation into 1MDB, which is the subject of investigations in other countries including the United States, Switzerland and Singapore.

Within days of taking power, Mahathir banned Najib from leaving Malaysia and reopened a government investigation into the alleged embezzlement of 1MDB money.