Three prison guards and 29 inmates were killed in a prison riot in Tajikistan that the government blamed on Islamic State militants.