Media playback is unsupported on your device Media caption Anwar Ibrahim says the opposition's election victory is "a new dawn" for Malaysia.

Reformist politician Anwar Ibrahim has hailed a "new dawn" for Malaysia on his release from prison, days after a stunning opposition election win.

Mr Anwar told jubilant supporters he fully backed his ally and former rival, Prime Minister Mahathir Mohamed.

Earlier he was pardoned from what was widely seen as a politically motivated conviction for sodomy.

Mr Mahathir, who sought the pardon, has promised to step aside for Mr Anwar to become prime minister within two years.

Once seen as a future leader, Anwar Ibrahim then fell out with the government. He was jailed for a second time three years ago on what he said were trumped-up sodomy charges.

After his release, he told a news conference he thanked the people of Malaysia, who "stood by the principles of democracy and freedom".

"They demand change."

Mr Anwar said he had forgiven Mr Mahathir and stressed he would give full support to the new government, though not immediately be part of it.

"I and Mahathir have buried the hatchet already, it was a long time ago," Mr Anwar told the news conference at his home.

For years he had headed Malaysia's opposition movement, which last week defeated the former ruling party for the first time in the country's history.

Last week's shock election victory followed a reconciliation between Mr Anwar and his 92-year-old erstwhile political mentor, who sacked and jailed him 20 years ago during his first stint as prime minister.

Image copyright Reuters Image caption Some prison officers celebrated Mr Anwar's moment of freedom with him

Mr Anwar walked free out of a hospital in the capital Kuala Lumpur where he had been undergoing treatment for a shoulder problem.

Supporters camped out at the hospital trailed him to the Istana Negara royal palace where he met Mr Mahathir before being pardoned by the king.

"Long live Anwar," supporters on motorbikes yelled as they pulled into the royal compound in support of their newly-freed leader.

"He is a symbol of freedom to Malaysians like me," 59-year old Ahmad Samsuddin told the BBC.

"Finally. It feels like the tide of change is turning in Malaysia after so many years of injustice. Today is a historic day with Anwar's release and will get even better."

Extraordinary twists and turns

The story of the relationship between Mr Mahathir and Mr Anwar is one of extraordinary twists and turns.

During the 1990s they were political allies, serving as prime minister and deputy prime minister respectively.

But Mr Anwar was sacked in 1998 and jailed a year later for abuse of power. In 2000 he was convicted of sodomy and given an additional nine-year jail term.

In 2004 his conviction was overturned and he led the opposition to unprecedented gains - though remained short of victory - in the 2008 and 2013 general elections.

A year later when he was heading into a state election he seemed likely to win, he was sent back to jail.

Events took a remarkable turn earlier this year, when Mr Mahathir announced he would join forces with the opposition and run for top office once again.

Media playback is unsupported on your device Media caption Malaysian voters react in 2018 to Mahathir Mohamad's victory over Najib Razak

Mr Mahathir said he was sick of the corruption allegations plaguing the incumbent, Najib Razak, another of his former allies.

One condition for Mr Mahathir being allowed to lead the opposition coalition was that he agreed to secure a royal pardon for Mr Anwar who remained popular with his supporters.

Mr Mahathir agreed and further said he intended to hand the prime ministerial post to Mr Anwar within two years.