HONG KONG — At least 27 people died in rioting in far western China on Wednesday, when protesters attacked a police station and government offices and the police fired on the crowd, state media said. It was the worst spasm of violence for years in Xinjiang, a region troubled by tensions between Uighurs, an overwhelmingly Muslim ethnic minority, and China’s Han majority.

The confrontation broke out in the morning in Lukqun, a township in Turpan Prefecture, the state-run news agency, Xinhua, reported, citing unnamed officials.

“Knife-wielding mobs attacked the township’s police stations, the local government building and a construction site, stabbing at people and setting fire to police cars,” the English-language report said. In the initial outburst of bloodshed, 17 people were killed, including nine police officers and security guards, and the police then fatally shot 10 rioters, it said.

The Xinhua report gave no explanation of what set off the confrontation. Nor did it give the ethnic background or other details of the rioters. Uighurs predominate in Turpan.