According to an Interior Ministry official, who was speaking on the condition of anonymity, the riot began late on Wednesday when one inmate regarded by the authorities as a member of the Takfiri Desh terrorist group attacked a prison guard and seized his assault rifle, presstv.ir reported.
An unnamed security official said police restored order hours later with the help of reinforcements.
The prison in Khujand, which lies around 300 kilometers (186 miles) north of the Tajik capital Dushanbe, is known for housing people convicted of extremism.
The two sources said at least 25 inmates were killed, as well as one warder and one policeman. The third source, also a security official, said three guards were killed.
Local officials confirmed there had been a riot, but provided no other information.
Local residents, however, said gunshots were heard from the prison area. They said police cordoned off all roads and highways connecting the city with neighboring Uzbekistan and Kyrgyzstan.
The Khujand directorate for penitentiary services denied that firearms were discharged in the prison but confirmed the extraordinary situation.
Tajikistan routinely reports detentions and convictions of Daesh militants. Last July, the terror group claimed responsibility for an attack which killed four Western tourists in the Central Asian country.