* State media blames overseas terrorist forces
* Foreign ministry says investigation proceeding
* Unrest signals failure of government to resolve ethnic tensions - analyst
China's state media has raised to 35 the death toll from unrest this week in far western Xinjiang region, and denounced the clashes, the deadliest in four years, as a "terrorist attack".
Xinjiang is home to a large Muslim Uighur community and violence focusing on its discontent had been confined recently to southern districts. The altercations in Shanshan county on Wednesday marked a return of unrest to Xinjiang's north.
Many Uighurs, Muslims who speak a Turkic language, chafe at what they call Chinese government restrictions on their culture, language and religion. China says it grants Uighurs wide-ranging freedoms and accuses extremists of separatism.
On Wednesday, gangs with knives attacked a police station and a government building and set fire to police cars. Twenty-four people died in clashes with police, including 16 Uighurs, state news agency Xinhua said.
According to Xinhua's latest dispatch on Thursday night, eight more died in the police response. It called the incident a "violent terrorist attack" and said the overall situation was now "on the whole, stable".
An officer at Shanshan county's public security, or police, bureau told Reuters by telephone that the cause of the riots and the ethnic origin of the attackers remained unclear.
Xinjiang government officials could not be reached.
A resident of Shanshan, speaking by telephone, said police officers were patrolling town streets, though he was unable to say if their presence was heavier than usual.
Foreign Ministry spokeswoman Hua Chunying condemned the icnident, though she stopped short of saying who was behind it.
"This is a violent terrorist surprise attack. There is no doubt about that," she said at a daily ministry briefing. "But with regard to who they are, or whether foreign forces were involved ... local public security is vigorously investigating."
CLASH IN THE SOUTH
A clash two months ago in Xinjiang's south, involving axes, knives and at least one gun, culminated in a house being burned down, with 21 people dead. The local government also described that incident as a "terrorist attack".
Uighurs make up 88 percent of residents in Shanshan county, according to the Global Times, a tabloid owned by the Communist Party's mouthpiece, the People's Daily.
Dilxat Raxit, the Sweden-based spokesman for the exiled World Uyghur Congress, blamed the "continued suppression and provocation" in Xinjiang for the conflict.
Duncan Innes-Ker of the Economist Intelligence Unit said the latest deaths highlighted the failure of Chinese authorities to resolve the region's ethnic and religious tensions.
"The government needs to come up with a new approach to dealing with ethnic and religious strains in China's minority regions, as its past efforts to address them with tight security and economic development have been a manifest failure," Innes-Ker said in a statement.
The Global Times renewed accusations by the authorities that "overseas terrorist forces" were to blame.
"Many foreign forces would like to see turbulence in Xinjiang, but those with a little analytical sense know this can hardly be reality," it said in an editorial.
Wednesday's unrest was the deadliest in Xinjiang since July 2009, when nearly 200 people were killed in riots pitting Uighurs against ethnic Chinese in the region's capital Urumqi, about 200 km (125 miles) northwest of Shanshan.