The incident happened on 23 April in a town in Kashgar prefecture. Fifteen officials or security personnel were among those killed. China said it was a planned attack by a "violent terrorist group".
But other accounts dispute this, attributing the confrontation to ethnic tensions in the restive region.
Xinjiang is home to the Muslim Uighur minority, who make up about 45% of the region's population but say an influx of Han Chinese residents has marginalised their traditional culture.
The 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.
Verifying reports from Xinjiang is difficult.
While foreign journalists are allowed to travel to the region, they frequently face intimidation and harassment when attempting to verify news of ethnic rioting or organised violence against government authorities.
The BBC team that visited the site of the incident to try to clarify details were taken by police to a government compound and subsequently ordered to leave.
The two men sentenced to death by Kashgar's Intermediate People's Court on murder and terrorism charges were named in state media as Musa Hesen, the co-founder of the "terrorist group", and Rehman Hupur.