IN AUGUST, three months after his opposition coalition trounced the Malaysian party that had ruled since independence, Mahathir Mohamad, the country’s 93-year-old new prime minister, travelled to Beijing. His aim was to tell President Xi Jinping that his country was now the Malaysia that can say no.

Dr Mahathir’s predecessor, Najib Razak, had hewed close to China. His loss at the polls resulted more than anything from the stench of corruption within his ruling United Malays National Organisation (UMNO). But his chumminess with China was also a factor. The two issues were entwined.

During Mr Najib’s rule, huge holes appeared in the finances of a state investment vehicle, 1MDB, which Mr Najib chaired. America’s Justice Department estimates that $4.5bn was stolen from the fund by insiders. (Around the same time, nearly $700m turned up in Mr Najib’s own bank accounts.) As 1MDB teetered, Chinese state entities stepped in, taking stakes in 1MDB ventures.

The relationship with China grew ever cosier. Chinese-funded projects in Malaysia were packaged as part of China’s Belt and Road Initiative, a global infrastructure-building scheme close to Mr Xi’s heart. Jack Ma of Alibaba, a Chinese tech giant, won the right to turn a site near Kuala Lumpur’s main airport into a Digital Free Trade Zone. Malaysia’s government tried to silence criticism of its state-to-state dealings. And China showed its gratitude. In the run-up to Malaysia’s general election in May, the Chinese ambassador appeared to lend open support to the ruling coalition. Many people were surprised that Dr Mahathir managed to win, despite UMNO’s gerrymandering. Mr Xi had reason to be aghast.

China is not used to recipients of its largesse challenging the terms on which it is offered. Yet growing numbers of them are struggling with debts to Chinese entities taken on to fund Chinese-staffed projects. The Centre for Global Development in Washington reckons that eight belt-and-road countries are at “particular risk of debt distress”, among them ones that border on China: Laos, Mongolia and Pakistan. That is why Dr Mahathir’s progress in disentangling his country from Chinese-funded ventures is being closely watched.

In Beijing Dr Mahathir was plain-speaking and deft. He said that Malaysia was cancelling the $20bn East Coast Rail Link, a massive belt-and-road project, as well as two oil pipelines in Sabah province. His message, in essence, was: very sorry—lovely projects, but since coming to office we’ve discovered we can’t afford them. Implicit was another point: we can’t afford them because we now know how inflated the costs are, and how skewed the deals are in China’s favour—or plain fishy. It appears the Najib government paid nearly 90% of the $2bn price of the Sabah pipelines, although they were only 15% complete. Part of a Chinese loan for them appears to have plugged financing gaps at 1MDB.

Since Dr Mahathir’s return, he has gone further, taking aim at a large, Chinese-led housing scheme in Johor state intended for wealthy investors in China. This week the prime minister declared that foreigners would not be given visas to live there. Most Malaysians, he complained, could not afford to live in the new development. (The government in Johor makes more reassuring noises to foreigners who might be interested.)

China has a tendency to launch into tirades against countries that confront it. In this case the response from Beijing has been muted. That may be partly because of Dr Mahathir’s careful choice of words. But Malaysia is an influential country in South-East Asia, a region that China wants to draw closer into its orbit. And China does not want to make enemies among belt-and-road countries. One of the main points of the project is to boost China’s influence over them. For other countries badly needing to renegotiate their deals with China, that is a lesson worth learning.

Of these, Pakistan, which also has a new prime minister, Imran Khan, is by far the biggest debtor to China. The China-Pakistan Economic Corridor, a collection of energy and infrastructure projects supposedly worth $60bn, is the biggest plank of China’s belt-and-road strategy. Not for the first time, Pakistan faces a balance-of-payments crisis. It wants out of its debt.

Mr Khan ought to do a Mahathir. And he is in an even better position. Far more than with Malaysia, there is a strategic dimension to China’s relations with Pakistan, says Husain Haqqani, a former Pakistani diplomat who is now at the Hudson Institute, an American think-tank. Officials in Beijing see Pakistan as a counterweight to India, China’s geostrategic rival. China needs Pakistan’s help in keeping Islamist extremism at bay. And it regards its neighbour as a vital route to the Arabian Sea. Unlike Dr Mahathir, Mr Khan himself seems not to grasp the problems of China’s debt embrace. But at least critics in Pakistan of the economic corridor are beginning to find their voice.

Debt divisions

China has more than its political ties with belt-and-road countries to consider. Chinese banks are getting worried about the safety of their lending. Commercial banks have sharply cut new belt-and-road financing since 2015. (So-called policy banks continue to lend.) And now the Belt and Road Initiative faces strong popular criticism at home. In part, the initiative is a victim of the Communist Party’s own propaganda: what debtors see as hard-to-service loans, state media paint as beneficent “aid”. That is a touchy word. At a summit in Beijing this week with African leaders, Mr Xi promised $60bn for the continent. Why, Chinese people asked on social media, is an indebted China spending so much abroad when it has pressing requirements at home? Censors rapidly shut down their criticisms of Mr Xi’s gesture.

China is right that many countries need more roads, railways and other infrastructure. But it is evident that the scheme it touts as a defining one of Mr Xi’s rule is losing its shine. Dr Mahathir’s trip may have taught some valuable lessons.