Malaysia’s aging former Prime Minister Mahathir Mohamad had to act earlier this week to save Prime Minister Najib Tun Razak from embarrassing legislation that would have given the Sultan of Johor executive powers to run the housing authority of the country’s second biggest state.

Eventually the legislation was amended to remove the threat. But once again it is Najib, in the eyes of political analysts in Kuala Lumpur, who is regarded as having suffered a blow to his political standing because of his failure to act. Former Deputy Prime Minister Musa Hitam, at 80 still a political force in Johor, also joined the fray to stop the legislation.

Although Najib’s position remains secure because there is no threat from anyone either inside or outside the United Malays National Organization, the country’s dominant ethnic political party, he is the subject of widespread criticism. He has come to be viewed as indecisive ever since the 2013 general election, in which the ruling national coalition lost the popular vote for the first time since 1969 although it maintained its majority in parliament,.

“Thank God for Mahathir,” said a prominent Kuala Lumpur opposition source. “I never thought I’d say that, but thank God for Mahathir.”

The hereditary rulers in nine of Malaysia’s 13 states supposedly merely perform ceremonial functions except in matters related to Islam, where they have powers of intervention. The Johor Sultan, Ismail Idris, was attempting to go far beyond that.

That is largely because during his 22-year period as Malaysia’s prime minister, Mahathir, now 88, engaged in a ferocious struggle to break the absolute power of the rulers, who take turns swapping the country’s kingship among them. Even after Mahathir broke their absolute power with legislation, the sultans have continued to get away with physical assaults and large-scale gambling debts in London and other casinos that have had to be paid from state coffers.

In 1993, in a speech before the Dewan Rakyat, or parliament, the then prime minister pushed through legislation that allowed commoners to criticize the sultans including the king without fear of the country’s Sedition Act. However, in recent years, Mahathir’s measure has been largely ignored, including by the former premier himself, as UMNO has played politics to use the sultans to stifle dissent.

Now UMNO got caught in its own contradictions. The Johor Sultan suddenly made a power play in a sweeping bill tabled by his ally, the state chief minister, Mohamed Khaled Nordin, in the Johor legislature that would have given the Sultan control over vast amounts of lucrative state land through the Johor Property and Housing Commission. The measure would have given the sultan the power to appoint board members and investigate the commission‘s books, among other functions.

It was the latest in a series of moves by the Johor monarch, which critics say have been designed to eventually effectively take full power in the state, the country’s second richest and one that is growing richer because of its proximity to Singapore across the narrow Singapore Strait. The vehicle is the huge Iskandar development region, covering the city of Johor Bahru and three adjoining towns. The Iskandar project, encompassing 2,217 hectares of land, is in effect becoming Singapore’s industrial and residential suburb. It is estimated that as much as 40 percent of infrastructure spending for the country under Najib’s Economic Transformation Program is being spent in the state.

Enter the Sultan, who since the project got underway in 2006 has assumed greater and greater control over the region. He has been accused privately of sanctioning kickbacks, money laundering and a variety of backroom deals. He was a college classmate of Chief Minister Khaled, whom he appointed to his job. But in the growing atmosphere of political repression of comments about the sultans, his misdeeds have remained unreported and the power play was largely hidden in shadowy language in Malaysia’s mainstream press, along with his behavioral antics.

Despite Mahathir’s legislation outlawing the use of sedition laws to stifle criticism of the sultans, for instance the late Karpal Singh, the former chief of the opposition Democratic Party, was convicted on appeal of sedition charges in February this year after he merely said in Kuala Lumpur in 2009, during a political squabble over the leadership of the state of Perak, that a decision by the Sultan of Perak could be questioned in court. Karpal was stripped of his legislative seat and fined. He was appealing the decision when he was killed in a car wreck.

That use of sedition against opposition members left Najib and UMNO in a quandary when it came to the Sultan of Johor, who is hardly a Boy Scout. Ibrahim was jailed on allegations that he had beaten people in nightclubs before he became sultan and committed other offenses including shooting a man in a nightclub after an argument during the 1980s. The charge was dismissed because of the then-prince's immunity. Ibrahim was also involved in two other separate assault cases.

In a 2005 case, a young woman reportedly was assaulted by Ibrahim after he accused her of two-timing him. His late father, Iskandar, who died in 2010 and for whom the Johor project was named, was alleged to have murdered two people but was not charged because of his immunity as a sultan. It was one of those murders that impelled Mahathir to push through laws removing the sultans’ immunity from prosecution.

Thus the ruling coalition and UMNO in particular were presented with a dilemma -- how to criticize the actions of a state ruler they themselves had deemed untouchable. Najib, say sources in Kuala Lumpur, simply abandoned the situation, ignoring a letter sent to him by Mahathir demanding he take action. Apparently it fell to Musa and Mahathir to force amendments in the legislation behind the scenes to stop the sultan’s ploy.

Part of Najib’s dilemma stemmed from the fact that UMNO has seen its local political clout diminish. Although it still controls 56 of the 74 seats in the State Legislative Assembly, it lost 18 seats to the opposition in the 2013 national election. In that relatively weakened state, political analysts said, opposing the sultan, who remains the figurehead of rural Malays, was considered politically unwise by Najib.

That was when Mahathir stepped in from Kuala Lumpur to criticize the legislation, along with Musa, who told the Straits Times Sunday edition that "If the allegations are true, then it will affect the fundamental principles of constitutional monarchy and parliamentary democracy. One cannot expect the people to keep quiet on the matter."

Ultimately the bill was modified to remove the sultan’s power to make appointments and vest it in the chief minister, which remains a continuing concern. It was passed on June 9. Mahathir himself remains suspicious, saying Chief Minister Khaled might succumb to the Malay tradition of considering the sultan the head of state.

"This is the Malay custom, if the sultan says something, it must be followed,” the former prime minister told Malaysiakini. "I am worried that it would not be the [chief minister] advising the sultan, but the sultan advising him."