Just before landing in Tokyo on Sunday, Mr. Panetta told correspondents aboard his jet that he was worried that territorial disputes in the Pacific raise “the possibility that a misjudgment on one side or the other could result in violence.”

Mr. Panetta said the United States was not taking sides in any of the region’s territorial disagreements, but advocated diplomacy to peacefully resolve them. One option, he said, would be for the feuding nations to follow a code of conduct advocated by the Association of Southeast Asian Nations.

Both China and Japan claim the disputed islands, although Japan has controlled them for over a century. China increased its pressure on Japan after the Japanese government purchased the islands from private owners. Japan says the move was to prevent nationalists from using the islands, but China has seen it as a step to solidify Japanese control. In response, China dispatched surveillance ships to the waters near the islands.

Complicating the diplomatic dispute, Japan’s newly appointed ambassador to China, Shinichi Nishimiya, died Sunday after falling ill last week in Tokyo, according to Japanese and Chinese news reports. He was appointed ambassador last week and was to assume his duties next month.

China’s state-run news media has made repeated calls for the islands to be given to China, which claims that it controlled them before Japan’s colonial expansion in the late 19th century. Both China and Japan are also involved in territorial disputes with other countries over separate island chains, some of which are thought to be surrounded by rich deposits of natural resources in the surrounding waters.

There was evidence on Sunday that some Chinese government officials were involved in the protests. In the western city of Xi’an, activists on the Internet identified one of the officials as the police chief.

The political analyst Li Weidong said the official tolerance fit a longstanding pattern of behavior in which the Chinese government uses mass protests to further its foreign policy goals. In a text message sent to friends and associates, Mr. Li compared the current protesters to the Boxers, a quasi-religious group that was used by the Qing dynasty to oppose foreign incursions in the late 19th and early 20th centuries.

“Beijing dares not to fight, but it’s unable to talk it over either,” Mr. Li wrote. “So it has to employ Boxers, using product boycott to press Japan.”