The violence erupted on Sunday at Yare I prison south of Caracas, and one of those slain was a relative of an inmate, said Iris Varela, the government's prisons minister.
It was the latest in a series of bloody clashes that have erupted inside Venezuela's overcrowded prisons and become a major problem for President Hugo Chavez's government.
Varela told state television that more than 20 people were killed but did not give a precise death toll or explain how the riot broke out. She said that as of Monday morning the situation at the prison was under control.
Varela said two groups of armed inmates had been fighting and that those behind the killings "are going to have to answer for this." She didn't provide details about how the inmate's relative died.
Carlos Nieto, an activist who monitors human rights in Venezuelan prisons, said an inmate's relative who was inside the prison told him the shootout began during family visiting hours. Nieto said the gunbattle lasted about four hours and involved groups fighting for control.
Nieto said the riot shows that the "most serious prison problem, the weapons possessed by inmates, hasn't been solved." He noted that less than a month ago, another bloody riot erupted at another prison in Merida state.
Violence has proliferated inside Venezuela's prisons, where inmates often obtain weapons and drugs with the help of corrupt guards.
The watchdog group Venezuelan Prisons Observatory says 560 people were killed in Venezuelan prisons last year. It also says the pace of the violence increased during the first half of this year, with at least 304 inmates killed.
Venezuela currently has 33 prisons built to hold about 12,000 inmates, but officials have said the prisons' population is about 47,000. Hundreds are held in Yare I, though a precise count wasn't immediately available.
Following a deadly armed uprising last year at the prisons El Rodeo I and El Rodeo II, just outside Caracas, Chavez announced plans for changes in the country's troubled penal system. The plans include building new prisons, improving living conditions for inmates and speeding trials for inmates who have yet to be sentenced.
Chavez's political opponents and groups that monitor inmates rights have criticized the government's response, calling it inadequate.