Twenty-one people, including police officers and social workers, were killed in violent clashes in China's ethnically divided western region of Xinjiang, officials said on Wednesday.

Gun fights broke out in Barchuk county in the west of the province after police went to search the home of locals suspected of possessing illegal knives, a report on Tianshan Net, a government-run news website, said.

Foreign ministry spokeswoman Hua Chunying said 15 police and social workers were killed in the violence, which occurred Tuesday -- among them 10 from China's mostly Muslim Uighur ethnic minority, who live mainly in Xinjiang. Two other Uighurs were injured.

Xinjiang, a region about twice the size of Turkey, is home to around nine million ethnic Uighurs. The region is regularly hit by unrest.

Officials and state media blame the unrest on "terrorists" but some experts say the government has produced little evidence of an organised terrorist threat, adding the violence stems more from long-standing local resentment.

Among the dead were six police officers, Hou Hanmin, director of the Xinjiang government news office, told AFP.

Another six "thugs" were shot dead in the violence. Hou said they were Uighurs. Another eight people were detained.

The foreign ministry's Hua said initial investigations indicated they were a gang planning to carry out violent terrorist activities.

"The current situation in Xinjiang is on the whole good. But there are a handful of terrorist forces doing whatever they can to try to disrupt the current trend of stability and development in Xinjiang," she said.

"Their schemes do not enjoy popular support and will not succeed."

China has repeatedly accused ethnic Uighurs of carrying out terrorist activities in the province, where 20 men were jailed in March on terrorism charges, which a Uighur rights group branded "repressive".

Riots between Uighurs and members of China's Han ethnic majority in Xinjiang's capital Urumqi in 2009 killed around 200 people, leading the ruling Communist Party to tighten surveillance and boost investment in the region.

The province saw more than half of China's "endangering state security" trials last year, but is home to less than two percent of the country's population, suggesting "ethnic discrimination", the Dui Hua Foundation advocacy group said.

According to official figures, 46 percent of Xinjiang's population is Uighur, while another 39 percent are Han Chinese, after millions moved to the area in recent decades.