Riots have killed 27 people in China's restive far western region of Xinjiang, Chinese state media report.

The violence broke out in Turpan prefecture early on Wednesday.

Police opened fire after a mob armed with knives attacked police stations and a local government building, Xinhua news agency quoted officials as saying.

There are sporadic outbreaks of violence in Xinjiang, where there are ethnic tensions between Muslim Uighur and Han Chinese communities.

Confirming reports from the region is difficult because information is tightly controlled.

Analysis China's state media have been quick to issue an official version of events regarding the latest round of violence in Xinjiang, but it will be tough to verify those reports. Xinjiang lies on China's remote north-west border and it is difficult for foreign media to travel there. Many people on both sides of the conflict are reluctant to speak to visiting journalists for fear of reprisals if they dispute the government's stance. Unfortunately Xinjiang usually hits international headlines when violence flares between the region's minority ethnic Uighur Muslims and the majority Han Chinese. Many Uighurs contend that their language and religion are being smothered by an influx of Han Chinese migrants. Xinjiang is a large geographic area rich in oil and gas deposits. Soon it will also become a major supplier of coal to China's energy-hungry cities. The region's fertile land also grows produce that is shipped to the rest of the country. The Han Chinese who move to Xinjiang hope to benefit from the region's untapped resources.

The violence occurred in Turpan's remote township of Lukqun, about 200km (120 miles) south-east of the region's capital, Urumqi.

The Xinhua news agency report, citing local officials, said rioters stabbed people and set police cars alight.

Seventeen people, including nine security personnel and eight civilians, were killed before police shot dead 10 of the rioters, it said.

At least three others were injured and were being treated in hospital, it added.

The Xinhua report did not provide any information on the ethnicity of those involved in the riot or on what sparked it.

But Dilxat Raxit, a spokesperson for the World Uighur Congress, an umbrella organisation of Uighur groups, told the Associated Press news agency the violence had been caused by the Chinese government's "sustained repression and provocation" of the Uighur community.

In 2009 almost 200 people - mostly Han Chinese - were killed after deadly rioting erupted in Urumqi between the Han Chinese and Uighur communities.

In April an incident in the city of Kashgar left 21 people dead.

Uighurs and Xinjiang Uighurs are ethnically Turkic Muslims

They make up about 45% of the region's population; 40% are Han Chinese

China re-established control in 1949 after crushing short-lived state of East Turkestan

Since then, large-scale immigration of Han Chinese

Uighurs fear erosion of traditional culture

The government said the violence began when "terrorists" were discovered in a building by officials searching for weapons.

But local people told the BBC that the violence involved a local family who had a longstanding dispute with officials who had been pressurising the men to shave off their beards and the women to take off their veils.

Uighurs make up about 45% of Xinjiang's population, but say an influx of Han Chinese residents has marginalised their traditional culture.

Beijing authorities often blame violent incidents in Xinjiang on Uighur extremists seeking autonomy for the region. Uighur activists, meanwhile, accuse Beijing of over-exaggerating the threat to justify heavy-handed rule.