BEIJING — At least 21 people were killed Tuesday in fighting in far western China between security officers and “gangsters,” according to a propaganda bureau spokeswoman for the regional government of Xinjiang, where the conflict took place.

Six of those killed were identified as gangsters, and eight more people in the gang were detained during the violence, according to accounts from the bureau and a report Wednesday on a regional news Web site, Tianshan. The other 15 fatalities were police officers and community watch workers or volunteers who died after the large gang herded them at sword point into a house and set the building on fire, said the propaganda spokeswoman, who gave only her surname, Hou.

The death toll was the highest reported in Xinjiang in many months, despite the fact that violence in the region, a vast western territory with many ethnicities, has been relatively common there in recent years. The violence has sometimes been rooted in ethnic conflict, particularly between ethnic Uighurs and the country’s Han majority, and other times has involved criminal gangs or attacks by individuals or groups against state organizations.

Ms. Hou said all 14 of the attackers were Uighurs who she said had been influenced by religious extremism and had been plotting a jihad since the end of last year, though there was no evidence they were working with foreign forces.