Anwar was once a high-flying member of the former ruling coalition but was convicted of homosexual sodomy and corruption after a power struggle in 1998 with Mr. Mahathir, who was prime minister for 22 years until 2003.

Voting opened on Saturday in a by-election that is expected to see charismatic Malaysian politician Anwar Ibrahim win a parliamentary seat and return to active politics as he prepare for his eventual takeover from Prime Minister Mahathir Mohamad.

Mr. Anwar was designated the successor to Mr. Mahathir, his former foe turned ally, after they set aside a bitter political feud and joined hands to win a stunning victory in May’s general elections. Mr. Anwar couldn’t participate in the polls due to a 2015 conviction for sodomy — a charge he alleged was politically motivated — but he was freed after receiving a royal pardon days after the polls.

Thousands of voters flocked to polling stations in the southern coastal town of Port Dickson, where Mr. Anwar is vying for a seat along with six other candidates. He is expected to easily win.

Two weeks of campaigning has seen bigwigs rallying for Mr. Anwar, including Mr. Mahathir and several ministers.

The Election Commission said it expects a 70 percent turnout from more than 75,000 voters in Port Dickson, a popular holiday retreat, and will announce results Saturday night.

Mr. Anwar was once a high-flying member of the former ruling coalition but was convicted of homosexual sodomy and corruption after a power struggle in 1998 with Mr. Mahathir, who was prime minister for 22 years until 2003. Mr. Anwar was freed in 2004 and in 2015 was convicted again of sodomy — charges he said were concocted to destroy his political career.

Angered by a monumental graft scandal at a state investment fund, Mr. Mahathir made a political comeback and the two forged a new opposition alliance in a gamble that paid off.

Mr. Mahathir, who is the world’s oldest leader at 93, has said he expects to be in office for at least two years and will keep his promise to hand over power to Mr. Anwar.

Mr. Mahathir rooted for his successor at a rally Monday night in Port Dickson, urging voters to support their alliance to fix Malaysia’s fiscal woes due to corruption by the previous government. It was the first time that the two men shared the same political stage together in 20 years.

Mr. Anwar, in speeches ending his campaign on Friday, promised he won’t interfere in Mahathir’s governance and will focus on parliamentary reforms.

“There will be lots of attention to [his margin of victory] but that is making a story about something that is not really important. The bottom line is that he will win and attention should focus on what he will do in parliament and his relationship with those in government,” said Bridget Welsh, political science lecturer at the John Cabot University in Rome.