Kuala Lumpur : Anwar Ibrahim, the twice-jailed former Malaysian opposition leader who is due to walk free on Wednesday after three years behind bars, says his country is on the verge of a new "golden era", adding, "I never lost hope" during his years in prison.

But in a world exclusive interview with Fairfax Media, the man who has led the country's reform, or "reformasi" movement for 20 years, cautioned his countrymen and women, saying "one election does not a democracy make".

The Malaysian Anti-Corruption Commission found evidence in late 2015 that around $10.6 million was transferred from a former subsidiary of state fund 1MDB into an account of then Prime Minister Najib Razak.

Anwar has spent eight of the past 20 years in prison on politically-motivated sodomy charges, and as his one-time rival, Mahathir Mohamad, secured a remarkable election victory six days ago, he was in hospital recovering from shoulder surgery.

But, he says, he never lost hope.

"I always believed in the wisdom of the people and that if we fought hard enough we would eventually prevail," he told Fairfax Media.

"At a time when democracy is in retreat around the world, I hope that the people of Malaysia have given some hope to people around the world clamouring for their own freedom."

Striking a note of caution, he reminded his fellow citizens of the deep, entrenched and systemic corruption that has infected Malaysia during the 61-year rule of recently ousted Barisan Nasional.

"The road ahead will challenge the best among us to deliver what we promised to the people," he said.

An urgent task was "respect for all Malaysians" – a reference to addressing racism embedded in the country's laws – "independence of the judiciary, rule of law, free media and proper separation of powers".

Anwar expressed confidence that he would be able to work with the 92-year-old former prime minister Mahathir Mohamad – his ally turned foe turned ally – who led the opposition Pakatan Harapan (Alliance of Hope) coalition to victory.

Malaysia's newly minted Prime Minister Mahathir Mohamad says that the king is willing to grant full pardon to jailed politician and former foe, Anwar Ibrahim immediately. He also announced plans to combat corruption in a country reeling from a billio

Even while in jail, and then while recovering from shoulder surgery in Cheras Rehabilitation Hospital in Kuala Lumpur, Anwar said he had detected a growing outrage among Malaysians over the "corrupt regime" of former prime minister Najib Razak, who has been accused of siphoning off billions of dollars in the 1MDB sovereign wealth fund scandal.

He told Fairfax Media the hardest thing about being in jail was the time away from his family.

Anwar Ibrahim in 2014, before his second stint in jail. AP

"My children were quite young during the earlier period of incarceration [from 1999 to 2003] and that was a difficult period for them and [his wife, new deputy prime minister Wan] Azizah," he said.

"It is pure agony to see your own children struggling because of decisions you made. This time [from 2015 to now] it is my children’s children who I missed deeply.

Anwar Ibrahim, right, Mahathir Mohamad, middle and Anwar's wife, Wan Azizah, at the hospital in Kuala Lumpur. Anwar Ibrahim's Facebook page

"But as a family, we were in concert that we cannot expect the people of Malaysia to take a risk for their freedom if we ourselves were not prepared to take those same risks.

At a time when democracy is in retreat ... I hope that the people of Malaysia have given some hope to people ... clamouring for freedom. Anwar Ibrahim

"As the days and weeks wore on I never lost hope. In fact, even from within the prison cell I sensed that the outrage against a corrupt regime was increasing by the day."

He said that, "in a free and fair election, we would have won 10 years ago".

Anwar is set to replace Mahathir as prime minister under a deal the pair agreed to before the election, though no date has been set for that transfer of power. Anwar was due to walk free on June 8, but the fast-tracking of his release - via an expected full royal pardon from Malaysia’s King Muhammad V of Kelantan, due Wednesday - will allow him to re-enter politics almost immediately, rather than waiting the five years required by the constitution.

Then Malaysian opposition leader Anwar Ibrahim, centre, is surrounded as he arrives at court in 2008. AP/File

Anwar must first win a seat in Parliament. He is likely to take Wan Azizah's seat if she resigns.

Anwar said that after working with Mahathir for many years, "I understand that he cares deeply about Malaysia and the people of Malaysia ... a new partnership was essential to overcome the deeply entrenched, corrupt system that was presiding over Malaysia".

"Our litmus test has always been supporting the reform agenda," he said.

"So long as there is sincere commitment to these principles, we have always welcomed new supporters. The animosity which preoccupies some observers is not an issue for me."

He spoke to Fairfax Media six days after the opposition's historic win in the country's 14th general election, which has ended 61 years of rule by the coalition.

In an ominous sign for the former prime minister, Najib and his wife Rosmah were slapped with a travel ban by Malaysia’s Immigration Department on Saturday, which stopped the couple from leaving for Jakarta.

Malaysian Prime Minister Mahathir Mohamad, centre, waves to crowds leaving National Mosque after performing Friday prayers in Kuala Lumpur. AP

The highs and lows of the relationship between Anwar and Mahathir are extraordinary.

Anwar served as Mahathir’s deputy prime minister for five years, when both were part of the now-defeated Barisan Nasional ruling party, from 1993 to 1998.

The pair fell out spectacularly and Anwar was jailed, during Mahathir's first period of 22 years as prime minister, for a five year period in 1999 on trumped-up sodomy charges.

Anwar returned to politics and led the opposition coalition at the 2008 and 2013 elections, improving their position but falling short of victory. He was then convicted and jailed again for a second five year on a second trumped up sodomy charge during the rule of Najib.

In late 2016, Mahathir came out of retirement, prompted by the massive corruption then evident in the government, and joined the opposition coalition led by Anwar's wife Wan Azizah, to blast Najib out of office.