BEIJING (Reuters) - Japan is "playing with fire" with plans to step up activity in the contested South China Sea through joint training patrols with the United States, China's Defence Ministry said on Thursday, warning it would not sit watching from the sidelines.

China claims virtually the entire South China Sea and has repeatedly denounced what it views as interference there by the United States and its ally, Japan.

Japan is strengthening its ties in the region, in particular with the Philippines and Vietnam, which contest China's claims to parts of the sea, and it aims to help build the capacity of coastal states in the busy waterway, its defense minister said this month during a visit to Washington.

Chinese Defence Ministry spokesman Yang Yujun, asked about Japan's plans, said it had constantly been trying to stir things up in the South China Sea for its own purposes.

"We must solemnly tell Japan this is a miscalculation. If Japan wants to have joint patrols or drills in waters under Chinese jurisdiction this really is playing with fire," Yang told a monthly news briefing.

"China's military will not sit idly by," he added, without elaborating.

Ties between Asia's two largest economies have long been overshadowed by arguments over their painful wartime history and a territorial spat in the East China Sea, among other issues.

Ships carrying about $5 trillion in trade pass through the South China Sea every year.

Brunei, Malaysia and Taiwan also have claims in the sea, which is also believed to be rich in energy resources and fish stocks.

In July, an arbitration court in the Hague said China's claims to the waterway were invalid, after a case was brought by the Philippines. China has refused to recognize the ruling.

(Reporting by Ben Blanchard; Editing by Robert Birsel)