"The message is clear, we in Permatang Pauh and in Malaysia, we demand change for freedom and justice," Anwar told a jubilant crowd who were chanting slogans of reform and freedom for Malaysia.

"We want an independent judiciary, we want the economy to benefit the vast majority not the corrupt few," he said.

The 61-year-old had pitted against Arif Shah Omar Shah, who represents the Barisan Nasional (BN) ruling coalition.

Ooi Kee Beng, a Malaysian expert at the Institute of Southeast Asian Studies in Singapore, said: "I think he feels he has to ride the momentum and given what he has experienced over the past few weeks, he will be more convinced than ever that he has to do that".

The results come despite the former deputy prime minister fighting charges of - and due to go on trial soon for - allegedly committing sodomy with Mohamad Saiful Bukhari Azlan, 23, Anwar's former aide.

'Dirty campaign'

Last month, the new sex allegation surfaced as Anwar stepped up his campaign to return to parliament.

He claims the BN "orchestrated the entire malicious, dirty campaign in time for this election", referring to the sodomy charge filed by Azlan.

Under Malaysian law, sodomy is illegal even if consensual and a conviction could see Anwar jailed for up to 20 years.

Election law rules that a person can contest an election unless he or she is convicted of an offence before polling day. 

Anwar, who was deputy prime minister before he was sacked on sodomy and corruption charges 10 years ago.

Anwar will again appear in court on September 10, meanwhile denying the sodomy charges made by his former aide.

Ibrahim Suffian, director of the independent Merdeka Centre, which conducted a telephone poll of 544 voters from Friday to Sunday, said more than half believed that Anwar was "capable of bringing change that will benefit the people regardless of race".

"I think it's a test of who protects the Malay interests the most, to which party will they entrust the political future."

Yang Razali Kassim, a senior fellow at the S. Rajaratnam School of International Studies at Nanyang technological university, said: "I would at least say that he has a vision of what the future economy should look like, he has a roadmap".