HONG KONG — China warned on Friday that tensions on the Korean Peninsula could spin out of control, as North Korea said it could test a nuclear weapon at any time and a United States naval group neared the peninsula — an American effort to sow doubt in Pyongyang over how President Trump might respond.

“The United States and South Korea and North Korea are engaging in tit for tat, with swords drawn and bows bent, and there have been storm clouds gathering,” China’s foreign minister, Wang Yi, said in Beijing, according to Xinhua, the state news agency.

“If they let war break out on the peninsula, they must shoulder that historical culpability and pay the corresponding price for this,” Mr. Wang said.

The comments were unusually blunt from China, which has been trying to steer between the Trump administration’s demands for it to do more to stop North Korea’s nuclear weapons program and its longstanding reluctance to risk a rupture with the North. The remarks also reflected, American experts said, an effort by the Chinese to throw responsibility for what happens back on Washington, after Mr. Trump declared, in several Twitter messages, that it was up to the Chinese to contain their neighbor and sometime partner.