When Malaysian Prime Minister Mahathir Mohamad took power in May 2018, it seemed clear that he would go cool on China.

But a year later, he is warming up his bonds with Beijing.

In his latest show of allegiance, the Malaysian leader made clear on which side of the fence he stands in the growing US-China rivalry when Washington showed its muscle on Chinese tech group Huawei Technologies.

In words that will grate in the Trump White House, Mahathir argued at the Nikkei Future of Asia conference on May 30 that it was time for the U.S. to accept that it was no longer necessarily ahead in the global technology race. He mocked American policy, saying: "If I am not ahead, I will ban you, I will send warships' -- that is not competition, that is threatening."

It is all a far cry from last year's election campaign, when Mahathir accused his predecessor, Najib Razak, of selling Malaysia's sovereignty to Beijing in return for costly loan-financed infrastructure schemes under China's Belt and Road Initiative.

Once in office, Mahathir followed up by successfully pressing Beijing to renegotiate plans for the China-backed East Coast Rail Line, or ECRL, change the route, cut out a tunnel and drop the price to Malaysia by $5 billion from the original $ 16.4 billion original plan.

But as the months went by, Mahathir switched tack. In the run-up to this year's BRI Summit -- a global leaders' gathering under Chinese president Xi Jinping -- the Malaysian leader lifted a suspension on another Chinese-financed project, Bandar Malaysia (Malaysian Township).

After earlier blocking the scheme on the grounds that it benefited only China he declared that Malaysian companies would profit from it after all.

Following a prominent appearance at the BRI Summit, Mahathir appears to have decided that the initiative is genuinely about peace, prosperity and shared development. The arch anti-imperialist, who suggested only last year that China might be the new colonial power, now seems to see China's global aspirations in an altruistic light.

It is as if he has totally forgotten not only his view of Najib's approach but the China-critical advice he offered his ASEAN partners, including the Philippines which he warned of the dangers of falling into China 'debt-trap' diplomacy, urging Manila to "regulate or limit influences from China."

So, what explains Mahathir's newfound confidence in China?

Good old-fashioned election politicking played a role. He needed to discredit Najib over his China ties because they fitted into his attacks on the former prime minister for financial greed and non-transparency. With the vote won, Mahathir could reassess.

Also, the growing uncertainty in the global economy and, especially the increasing trade dispute between the U.S. and China, seem to have convinced the Malaysian leader that he needed Beijing's economic power and largesse after all.

Finally, while Najib leaned heavily toward China, he was not suspicious of the West or the U.S. He enjoyed a good relationship with former President Barack Obama, and was keen on the Trans Pacific Partnership agreement (TPP), which Obama backed and from which Beijing was excluded. By contrast, Mahathir, who spent years as a critic of western colonialism and neocolonialism, would never easily have invested in ties with the U.S., even if the unpredictable Donald Trump had not made the White House.

And what are the consequences of Mahathir's China pivot?

It appears that Beijing will gain a firmer foothold in the region with the implicit support of South East Asia's elder statesman, Mahathir. At least the silencing of his invective against China, will make life a lot more comfortable for Beijing in the region, especially as Xi, from his side, has pledged to listen more to the views of China's BRI partners.

While Malaysia has been a big proponent of ASEAN and the central role ASEAN should play for its ten members, including in trade, Mahathir may now put his support behind completing the long and much-delayed negotiations for the broad Regional Comprehensive Economic Partnership (RCEP), which would include China.

The Malaysian leader might hope RCEP could facilitate moves to turn Malaysia into a Chinese investment hub for the region. With the U.S.-China trade war developing, Malaysia could be an alternative export production hub for Chinese companies, with sufficient local content to overcome Trump's barriers.

Meanwhile, Mahathir may now have fewer concerns about expressing his reservations over the Comprehensive and Progressive Agreement for Trans-Pacific Partnership (CPTPP) -- which is now being ratified and implemented after Trump pulled out of its predecessor, the TPP.

Mahathir, always a TPP doubter, will have less reason to have Malaysia ratify the new pact, now that the U.S. is out of the accord. Nor will he have much truck with the ideas of those CPTPP signatories who see it as a way of containing China. Malaysia is in any case disturbed by key elements of CPTPP including intellectual property rights, investor-state dispute settlement and government procurement.

When it comes to security issues, Mahathir, like most other ASEAN leaders, would prefer that the U.S.-China rivalry avoid the region and allow ASEAN to stick with its long-standing preference to manage its own affairs without outside interference.

Importantly, Malaysia's foreign minister, Saifuddin Abdullah, has rebuffed China's proposal that the bilateral elements of the complex South China Sea dispute be resolved on a bilateral basis.

Malaysia says the dispute -- which also involve the Philippines and Vietnam -- are an ASEAN matter, wanting to preserve the unity of the member states.

But, in a veiled warning to Washington, Mahathir has declared that it is not right to have warships in the South China Sea, a reference to frequent American patrols that have annoyed China.

Certainly, there is no reason why Mahathir would jeopardize his China ties by involving himself in the emerging Indo-Pacific strategy being developed by the U.S., Japan and other American allies on limiting China's military expansion in the region.

In sum, the outspoken criticism Mahathir briefly voiced against China is passing into history. His future ties with Beijing may be at least as warm as Najib's. His ties with Washington much cooler. The idea that he might in some way resume his former role as the world's last non-aligned leader is fading fast.

Shankaran Nambiar is a senior research fellow at the Malaysian Institute of Economic Research. He is author of the recently published book, "Malaysia: An Economy at the Edge of Transformation."