The lock-up in the Pacific coast city of Mazatlan was quickly brought under control and investigators found two pistols and an assault rifle inside, said Martin Gastelum, a spokesman for the Sinaloa state prosecutors' office.
Gastelum said all the dead inmates were killed by other prisoners. He did not say whether police fired any shots while restoring order.
Sinaloa state Public Safety Secretary Josefina Garcia told Radio Formula that one of the two police officers wounded was in serious condition.
Garcia said 17 of the dead were among the inmates attacked and three were with the attackers.
Local media said those attacked were apparently members of the Zetas drug gang, which is battling the powerful Sinaloa cartel, but officials were unable to confirm that.
Many of Mexico's most powerful drug traffickers hail from Sinaloa, a key smuggling corridor and cultivation area for marijuana and opiates. The northwestern state, and Mazatlan in particular, are rife with turf battles among drug gangs.
Mexico's drug gangs frequently try to break their members out of prison, by staging attacks from the outside or buying off prison officials. But there was no immediate confirmation Monday's shootings involved a prison-break attempt.