At the age of 92, Mahathir Mohamad, was elected as the new Malaysian Prime Minister after a stunning election victory against scandal-haunted leader Najib Razak.
Mahathir has said he expects to run the government for up to two years during an uncertain transition period but has signalled the reins would be turned over to Anwar, who lost his parliament seat with his criminal conviction.
Perhaps the country's best known prisoner, Anwar was serving a sentence of five years for the crime of sodomy, despite claiming that the charges were brought against him for politically motivated reasons.
Now 70, he was imprisoned again in 2015 during Najib's rule - after making historic gains as the head of the opposition at the 2013 elections.
Anwar has cast a long shadow over Malaysian politics for decades.
After being freed in 2004, Anwar was jailed a second time.
Datuk Seri Anwar Ibrahim said today he is not anxious about making a political comeback, fresh after he was released from prison.
His daughter, lawmaker Nurul Izzah Anwar, said the Pardons Board will meet on Wednesday, after which Anwar is expected to be released.
Talib Ibrahim, 60, a supporter waiting at the Kuala Lumpur hospital, said Anwar's release was "good for the country". "Mahathir is keeping to his deal".
Mahathir, with whom Anwar joined forces to win last Wednesday's election, was at the palace to greet him. But I have to do it because they appointed me as Prime Minister.
Neymar Wins The France Player Of The Year Award
Paris Saint-Germain superstar Neymar has been named France's Player of the Year at an awards ceremony in Paris on Sunday. Neymar scored 19 league goals and set up another 13 in only 20 games for French champion PSG .
"Prison officers and staff. were kind, they were compassionate, they were very supportive", he said of his time in jail.
Analysts say tensions in the new government are possible due to the dominance of the two leaders Mahathir is the chairman of the alliance and Anwar is its de facto leader.
Differences have already cropped up between supporters of Mahathir and Anwar over cabinet positions and Anwar's role.
The highs and lows of the relationship between Anwar and Mahathir are extraordinary.
At a later press conference, Anwar seemed giddy at the pace of events, reflecting that he had gone from "prison to the palace" in just a day. "I've been there, right behind", said the man who was once Malaysia's deputy prime minister.
The opposition alliance united by Anwar brought together odd bedfellows: an ethnic Chinese pro-democracy party, the conservative Islamic PAS, and Anwar's own racially diverse party.
When Mahathir was prime minister in the 1990s, Anwar was his deputy and clear heir-apparent. That black eye has become the logo of his People's Justice Party.
Pakatan Harapan leaders had asked the monarch for the pardon last week.
But in one of Malaysia's many political twists, Mahathir came out of retirement, determined to oust Najib over accusations that he had presided over the looting of billions of dollars from a state investment fund, a scandal that has tarnished Malaysia worldwide.
Sankara Nair, Mr Anwar's lawyer, said the opposition politician had seemed "composed and was quite upbeat, but also quite nervous" as he prepared to leave the the hospital.