Malaysia’s former deputy prime minister Anwar Ibrahim, jailed for sodomy three years ago, has walked free from prison after receiving a royal pardon.

Anwar’s release is the first big success of the newly elected governing coalition, Pakatan Harapan, led by 92-year-old Mahathir Mohamad, which was swept into power after a shock election victory last week.

At 11.30am on Wednesday, a frail but jubilant Anwar emerged from Cheras rehabilitation hospital in Kuala Lumpur, where he has recently been serving his sentence after an operation on his shoulder. He waved to the gathered crowds before getting into a car to go to the National Palace, where he met the king for an hour to formalise his pardon.

Bhavan Jaipragas 八万 (@jbhavan) Anwar Ibrahim wanted to deliver a few remarks but the media scrum was too crazy. He ducked into the waiting car that will take him to the National Palace. What a moment in history. #GE14 pic.twitter.com/PEXQjtkzov

“Today is a new beginning. It is a new chapter in our country,” he said.

Few in Malaysia have been persecuted for their political views and popularity like Anwar, a man with three prison sentences and 11 years in jail to his name. The pardon was filed on the basis of a “miscarriage of justice”, thus clearing his name entirely.

It was his first taste of freedom since 2015, following a prison sentence widely perceived as politically motivated; a manoeuvre by former prime minister Najib Razak to get rid of a feared political rival who had run against him – and won the popular vote – in the 2013 general election.

Speaking at a press conference at his home following his release, Anwar said he bore no personal malice towards either former prime minister Najib or Mahathir, who was responsible for his first prison sentence in 1999.

“I have forgiven him,” said Anwar when asked about Najib. “But the issue of injustice towards the people, crimes committed against the people, endemic corruption that has become a culture in this country, that he has to answer for.”

Ensuring the full royal pardon of Anwar was a key part of the agreement between Mahathir and the opposition when it was decided in January he would swap sides and run as their leader in the election, united by a joint desire to oust Najib. Mahathir’s previous 22-year reign as prime minister was as head of the ruling party Umno.

A beaming Anwar, sitting next to his wife, Dr Wan Azizah – who is now deputy prime minister – stressed he was no rush to return to politics, and would be spending some time with his family and speaking at Harvard, Stanford and Georgetown universities. Under the agreement with the opposition, Mahathir will serve as prime minister for two years, before handing power, finally, to Anwar.

“I don’t need to serve in the cabinet for now,” said Anwar. “I have informed Dr Mahathir it is very kind to offer but I have said no, it is better that you and Azizah and the team continue and allow me to take some time with the family ... I think I need that time, that space.”

The release also marks the next phase in Mahathir and Anwar’s turbulent relationship, which has been a decisive part of Malaysian politics for over three decades.

At last, tyranny has ended in Malaysia. Now let’s build an open society | Nurul Izzah Anwar Read more

Anwar was adamant that he and Mahathir had buried the hatchet, and said he trusted him to implement the opposition reform agenda.

“One of the very well-known world statesmen was joking with me: ‘Anwar, are you sure, are you telling me the truth. Look at me and tell me say that you’ve forgiven him [Mahathir]?’,” recounted Anwar.

“I looked at him and I said: ‘My interest now is the wealth of the nation. I have forgiven him. He has proven his mettle, he has made sacrifices ... he has even facilitated my release. Why should I have any malice towards him?”

Anwar began his career in politics as Mahathir’s protege in the early 1980s – having already spent almost two years in jail for political protest – and quickly rose through the ranks to become deputy prime minister in 1993.

His first downfall came in 1998, when he and Mahathir fell out over alleged cronyism and economic crisis, and Mahathir began to fear Anwar’s vast popularity. Anwar was ousted from office and then found himself charged with sodomy and corruption.

The resulting court case, the longest in Malaysian history, was an exercise in humiliation for Anwar, who was accused of sodomy with his speechwriter and wife’s chauffeur.

“I cannot accept a man who is a sodomist to become the leader of this country,” said Mahathir at the time. Even though the evidence was flimsy and much of it coerced, Anwar was found guilty in 1999 of corruption and in 2000 of sodomy, landing him with a cumulative 15-year prison sentence.

Malaysia: Mahathir says Najib must 'face consequences' in corruption inquiry Read more

He was allowed out in 2004, having spent six years in solitary confinement, and was allowed back into politics in 2008, when he ran as opposition leader in the election. But his reappearance on the political scene was not without ramifications. In 2010, he was put on trial again for sodomy, in hearings that went on for two years. He was acquitted, then ran again as opposition leader in the 2013 elections, gaining more of the votes, but still losing to Najib.

But a year after Najib won the election, Anwar’s acquittal was overturned and he was sentenced to five years in jail for sodomy, where he has remained since.

Throughout his ordeal, Anwar has remained a uniting figure for the opposition, and his release will be decisive for the Pakatan Harapan coalition, who are already grappling with tension among their divided ranks of Anwar’s PKR party, Mahathir’s party Bersatu, the DAP and Amanah.

His release was greeted with jubilation nationwide. Among the crowds at the hospital was Anwar’s old university friend, 78-year-old Azidin Mahmud, who travelled 300 miles to see the release. “He has suffered too long but he really is a champion of justice,” said Azidin.

“I saw him first speaking at the University of Malaysia Speaker’s Corner in 1968. Then we travelled together around all Malaysia, fighting for the freedom of the poor man. I am very very happy to see my friend finally released today. Long live Anwar Ibrahim.”