By Michael Martina

BEIJING (Reuters) - China and Japan must ease tension in the disputed East China Sea to avoid severe "unintended consequences", U.S. Ambassador to China Gary Locke said on Thursday, days before he steps down as Washington's first Chinese-American envoy in Beijing.

Asia's two largest economies have been locked in a war of words after Japanese Prime Minister Shinzo Abe visited Tokyo's Yasukuni Shrine on December 26, which China sees as a symbol of militarism because it honors wartime leaders along with millions of war dead.

"The last thing we need is some unintended incident that leads to unintended consequences, very severe consequences," Locke, who departs China on Saturday to be replaced by U.S. Senator Max Baucus, told reporters.

"It's important that both sides lower the temperature and focus on diplomacy," he said, adding that the United States takes no sides in the territorial dispute that flared in 2012 over a group of uninhabited islets in the East China Sea.

Sino-Japanese ties have been plagued by China's bitter memories of Japan's occupation of parts of the country before, and during, World War Two.

China's Defense Ministry kept up the rhetoric against Japan on Thursday, saying its army, as the defenders of the country's sovereignty, would "never allow a repeat performance of historic tragedies".

China and the United States have numerous diplomatic disagreements in the region, including China's moves to assert sovereignty in the South and East China Sea and U.S. support for self-ruled Taiwan, claimed by Beijing as a wayward province.

Locke's 2-1/2 year term was marked by a series of high-profile diplomatic incidents between Washington and Beijing.

In 2012, blind rights activist Chen Guangcheng escaped from house arrest to seek refuge in the embassy and later travelled to New York to study on a U.S.-brokered deal which overshadowed high-level U.S.-Chinese foreign policy and economic talks.

Locke said the handling of the Chen incident was "a testament" to how well the two governments worked to address a sensitive human rights matter.

Story continues

He was also ambassador when Wang Lijun, the former Chongqing police chief, went to ground in the U.S. consulate in nearby Chengdu in February 2012 until he was coaxed out and placed under investigation by China's ruling Communist Party.

Wang's flight triggered revelations about the murder of British businessman Neil Heywood in November 2011 by Gu Kailai, the wife of the controversial top official in Chongqing, Bo Xilai. Bo was jailed for life in September for corruption and abuse of power in the worst political scandal since the 1976 downfall of the Gang of Four led by the widow of former leader Mao Zedong at the end of the Cultural Revolution.

The Wang incident was an "intense 48-hour period, but one that I think ended up very, very well and, of course, has perhaps changed the trajectory of politics here in China", Locke said, without elaborating.

Locke, who was a governor in Washington state and also served as commerce secretary, said he was not considering another run for office after leaving Beijing.

"I will be very active in helping other candidates, but I have no intention of being a candidate for any other office myself," he said.

(Additional reporting by Ben Blanchard and Li Hui; Editing by Michael Perry and Clarence Fernandez)