The vote in Anwar's home state of Penang cemented a stunning comeback for the former deputy prime minister, who was dimmised a decade ago from his position and jailed on sodomy and corruption charges widely seen as politically motivated.
"I thank God who has been with me through this gruelling election process. I thank the voters," Anwar said as he arrived at the counting centre where some 30,000 supporters were holding a wild celebration.
"The message is clear ... we have made a demand for change, for freedom and for justice.
"The people do not want to be exploited. We want an economic order that protects all the people."
The 61-year-old was 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".
As Anwar stepped up his campaign last month to return to parliament, he faced news charges of allegedly committing sodomy with Mohamad Saiful Bukhari Azlan, 23, his former aide.
He claims the BN "orchestrated the entire malicious, dirty campaign in time for this election", referring to the sodomy charge filed by Azlan.
'Capable of change'
Under Malaysian law, sodomy is illegal even if consensual, and a conviction could see Anwar jailed for up to 20 years.
Anwar will again appear in court on September 10 to deny the sodomy charges against him.
Ibrahim Suffian, director of the 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".