Dr Mahathir Mohamad won a stunning victory in Malaysiainfo-icon's election, ending the six-decade rule of Prime Minister Najib Razak's party in a landmark shift for the Southeast Asian nation.

Mahathir, Malaysia's longest-serving Premier who defected to the opposition to take on Najib, will return to power at the age of 92.

His four-party Pakatan Harapan alliance won at least 112 of 222 parliamentary seats in the vote, official figures from the election commission showed.

"We are not seeking revenge," Mahathir said. "What we want to do is to restore the rule of law."

Khairy Jamaluddin, a member of Najib's Cabinet, said the prime minister plans to hold a press conference.

"We're going to accept the will of the people," he said. "Whatever it is, we need to respect the will of the people."

The result represents a monumental shift in a nation long defined by racial politics that hasn't seen a transfer of power since independence in 1957.

It's also a win for democracy in Southeast Asiainfo-icon, where generals and authoritarian leaders often lock up opponents and stifle free speech.

"It's a new beginning for Malaysia," said Ahmad Martadha Mohamed, an associate professor at Universiti Utara Malaysia College of Law.

"This is a repudiation of Najib's government from all walks of life from the very rural northern states to the more industrial southern coast," said Bridget Welsh, a Southeast Asia expert at John Cabot University in Rome.

"The person who has made this happen is Mahathir. He has been a significant game changer. He made people feel that a transition of power is possible," said Welsh, in Kuala Lumpur to observe the polls.

Mahathir implored government officials to "do what is right according to the constitution and the laws of this country."

He had previously run the country from 1981 to 2003, and wielded power even after he stepped down.

The opposition alliance celebrates at a hotel in Kuala Lumpur, Malaysia. Photo / AP

The vote showed that Mahathir still knows how to win electionsinfo-icon. The victory was dominant: He swept traditional government strongholds like Johor, Kedah and Negeri Sembilan and neutralised Najib's advantage in the Borneo states of Sabah and Sarawak.

What's more, Mahathir appeared to decisively win over ethnic Malay voters that had long underpinned the ruling party's success. The mostly ethnic Chinese Democratic Action Party, previously the largest opposition party, was on pace to win fewer seats than in 2013.

For Mahathir, the fight against his former protege was particularly ugly.

The two fell out over a myriad policy issues, including Najib's decision to abolish the Internal Security Act, his performance in the 2013 general election and a money laundering scandal involving state investment firm 1MDB. Najib has denied wrongdoing.

Ahead of the vote, Mahathir had called Najib a "thief" who "lives in fear even of my photos." Najib countered by saying Mahathir is "obsessive about control, calling the shots."

Malaysian police officers fire tear gas towards opposition party supporters in Putrajaya, Malaysia. Photo / AP

On the campaign trail, the opposition mainly focused on bread-and-butter issues. Najib faced rising discontent over a goods-and-services tax that helped inflation accelerate last year at nearly the fastest pace in a decade.

What comes next is unclear. Mahathir helms an unwieldy four-party coalition that includes Malaysia's largest ethnic Chinese party, and he plans to step aside once de facto opposition leader Anwar Ibrahim gets out of jail on a sodomy charge. Mahathir said he would seek a pardon for Anwar.

"I have to manage four presidents of four different parties," Mahathir said. "It's going to be a headache."

Mahathir has pledged to set term limits for prime minister and reduce its power, while promising to scrap the GST within 100 days in power.

It's uncertain whether the outcome will fundamentally reshape race relations in Malaysia.

Najib's party had long staked its legitimacy on providing preferential treatment for the bumiputera, or "sons of the soil," which include ethnic Malays and indigenous groups.

Mak Hon Hoe, a 46-year-old ethnic Chinese voter, on Wednesday deplored the fact that Malaysians were separated in different racial categories.

"I want to see a fairer system," he said while casting his ballot. "Race is still an issue. We want a Malaysian identity."