KUALA LUMPUR, Malaysia—Former leader Mahathir Mohamad was terminated on Friday as an adviser to state oil firm Petroliam Nasional Bhd., or Petronas, over his alliance with the opposition, which is demanding the resignation of embattled Prime Minister Najib Razak.

The prime minister’s office said in a statement that Mr. Najib’s cabinet has agreed unanimously to terminate Dr. Mahathir’s service after deciding that since he was “no longer supporting the current government, he should no longer hold any position related to the government.

’’The statement said a declaration by Dr. Mahathir and opposition leaders last week “aims to topple the democratically elected government led by the prime minister and is therefore against the law and the Federal Constitution.”A spokesman for Dr. Mahathir said he had no immediate comment.

Dr. Mahathir, 90 years old, lent his heft as Malaysia’s longest-serving prime minister to politicians and activists urging Mr. Najib to step down over a growing scandal surrounding a state investment fund he leads.

The former leader, who quit the country’s ruling party last month, has been a staunch critic of Mr. Najib. He remains an influential figure in Malaysia for the way he helped engineer decades of economic growth.
.

Pressure on Mr. Najib has grown since The Wall Street Journal reported last year that government investigators had found that hundreds of millions of dollars had entered his personal bank accounts via banks, companies and other entities linked to 1Malaysia Development Bhd., or 1MDB, the state investment fund.

Mr. Najib, 62 years old, has denied wrongdoing or taking money for personal gain. The 1MDB fund also has denied wrongdoing or paying any funds to the personal accounts of the prime minister, and has said it is cooperating with investigations. Malaysia’s attorney general said the funds were a legal political donation from Saudi Arabia and that most of the money was returned.

Dr. Mahathir assumed the role of adviser to Petronas after stepping down as prime minister in 2003, after 22 years in power. In office, he was personally involved in steering the overseas expansion of Petronas and expanding its role as an engine of economic development.

He briefly quit as adviser in 2013, saying that he made the decision following his physician’s s advice, but was asked by Mr.Najib to reconsider. His offices as adviser were in Kuala Lumpur’s landmark Petronas Twin Towers, once the world’s tallest buildings.

The termination comes at a time when Malaysia’s only Fortune 500 company is cutting spending by some $11.4 billion over the next four years and is currently reducing 1,000 jobs as it navigates an environment of slumping oil prices.

Dr. Mahathir remains the chairman of Malaysia’s national car maker, Proton Holdings Bhd., a post to which he was appointed in June 2014.