Tajikistan's Justice Ministry said the riot broke out late on Sunday in the prison in the city of Vakhdat, 10 km (six miles) east of the capital Dushanbe, as militants armed with knives killed three guards and five fellow prisoners.
The militants then torched the prison hospital, took several inmates hostage and tried to fight their way out. Security forces killed 24 militants in the battle to restore order in the prison, the ministry said. The prison houses 1,500 inmates.
Among prisoners who were killed were two senior members of the Islamic Renaissance Party of Tajikistan (IRPT), an Islamist party outlawed by the government of President Imomali Rakhmon in 2015. Another was a prominent Tajik cleric convicted on charges of calls to overthrow the government.
The authorities said one of the instigators of the riot was Bekhruz Gulmurod, a son of Gulmurod Khalimov, a Tajik special forces colonel who defected to Islamic State in 2015 and, according to the government, has since been killed in Syria. The ministry did not specify whether the younger Gulmurod was among those killed in the riot.
Hundreds of people from the impoverished former Soviet republic of 9 million are believed to have joined Islamic State, which at one point controlled large swathes of land in Syria and Iraq.
The group, which has now lost its strongholds but continues underground operations, claimed responsibility for another Tajik prison riot last November, which followed a deadly attack by its followers on Western tourists in Tajikistan in July 2018.
The government of the Persian-speaking nation which borders Afghanistan fought against Islamists - who were allied with nationalists and liberal democrats - in a civil war in the 1990s which killed tens of thousands of people.Tajikistan's leader Rakhmon is the longest-serving ruler in the former Soviet Union, having taken power shortly after independence, and tolerates little dissent.