When I was in Beijing over the Easter holidays, I was told about a Chinese couplet that goes: 'Japan saved the Communist Party; Islam rescued China.'
Japan 'saved' the Communist Party because by invading China in the 1930s, it badly weakened the Nationalist government of president Chiang Kai-shek.
When Japanese premier Kakuei Tanaka visited Beijing in 1972 to normalise relations, Mao Zedong told him there was no need to apologise for the Japanese invasion. In fact, Mao said, he should thank Japan because otherwise the Communists could not have defeated the Nationalists.
The second part of the couplet refers to the al-Qaeda brand of Islam, which 'saved' China by launching the September 11 attacks on the United States. When George W. Bush assumed office as president in 2001, he called mainland China a strategic competitor and the new administration viewed it as America's next enemy.
However, the September 11 attacks drastically changed the American focus, directing its attention to Afghanistan and Iran instead of the mainland. It is little exaggeration to say that bin Laden saved China from American containment and isolation.
Osama bin Laden, who was killed by US Navy Seals last week, transformed America's strategic outlook by launching the terrorist attacks on the US a decade ago.
At the time, China's then president Jiang Zemin responded to the terrorist attacks by immediately sending condolences to Bush and promising to co-operate with Washington in the war against terrorism.
Beijing did not object when, for the first time, the US set up military bases in Central Asia adjacent to its borders as part of its campaign against al-Qaeda in Afghanistan, which at the time was under Taliban rule.
Of course, while the US was the target of the terrorist attacks, China was a major beneficiary. During the past decade, Beijing has been able to focus single-mindedly on economic growth. It more than quadrupled the size of its economy in nine years and, last year, became the world's second largest economy.
Meanwhile, the wars in Afghanistan and Iraq have cost the US well over a trillion dollars and claimed the lives of 6,000 American soldiers. This kept Washington's attention focused on the Middle East, while China increased its global influence.
Beijing's reaction to bin Laden's death has been unambiguous. It applauded the killing of the al-Qaeda leader as 'an important event and positive development'. Nothing was said about the shooting down of an unarmed man, or of the denial of a court trial for him. Even more interestingly, there was no reference to violation of Pakistan's sovereignty by the US or interference in that country's internal affairs.
China's primary emphasis is on the need for international co-operation against terrorism as well as eliminating the breeding ground of terrorism by addressing the root causes.
The silence on US interference is significant, given China's long-held belief in the sanctity of national borders and the fact Pakistan is one of its closest friends. China needs Pakistan's co-operation in its own campaign against pro-independence Uygurs in Xinjiang, whom Beijing depicts as terrorists. Thus, it is unlikely to go too far in condoning American activities to which Pakistan objects.
Pakistan's military is now warning the US never to violate its sovereignty again. That being the case, China is also unlikely to tolerate a second American operation against, say, Ayman al-Zawahiri, widely seen as a successor to bin Laden.
But by not criticising Washington for sending a specially trained team into another country to assassinate the national of a third country, China is showing its understanding of the American position in a special case - that of a country that is exercising its right of national self-defence.
Frank Ching is a Hong Kong-based writer and commentator. Follow him on Twitter: @FrankChing1