After carrying out the killings the inmates would return to their cells, the Attorney General's Office said in a revelation that was shocking even for a country wearied by years of drug violence and corruption.
"According to witnesses, the inmates were allowed to leave with authorization of the prison director ... to carry out instructions for revenge attacks using official vehicles and using guards' weapons for executions," office spokesman Ricardo Najera said at a news conference.
The director of the prison in Gomez Palacio in Durango state and three other officials were placed under a form of house arrest pending further investigation. No charges have yet been filed.
Prosecutors said the prison-based hit squad is suspected in three mass shootings, including the July 18 attack on a party in the city of Torreon, which is near Gomez Palacio. In that incident, gunmen fired indiscriminately into a crowd of mainly young people in a rented hall, killing 17 people, including women.
Police found more than 120 bullet casings at the scene, and Najera said tests matched those casings to four assault rifles assigned to guards at the prison.
Similar ballistics tests linked the guns to earlier killings at two bars in Torreon, the capital of northern Coahuila state, he said. At least 16 people were killed in those attacks on Feb. 1 and May 15, local media reported.
Najera blamed the killings on disputes between rival drug cartels. "Unfortunately, the criminals also carried out cowardly killings of innocent civilians, only to return to their cells," he said.
Coahuila and neighboring Durango are among several northern states that have seen a spike in drug-related violence that authorities attribute to a fight between the Gulf cartel and its former enforcers, known as the Zetas.
Mexico has long had a problem with investigating crimes, catching criminals and convicting people. Reports estimate less than 2 percent of crimes in Mexico result in prison sentences. But Sunday's revelation suggests that even putting cartel gunmen in prison may not prevent them from continuing to commit crimes.
Interior Secretary Francisco Blake said the revelation "can only be seen as a wake-up call for authorities to address, once again, the state of deterioration in many local law enforcement institutions ... we cannot allow this kind of thing to happen again."
Also Sunday, Mexican federal police announced the arrest of an alleged leading member of a drug gang blamed in recent killings and a car-bombing in the violence-ridden border city of Ciudad Juarez, across from El Paso, Texas.
Police described Luis Vazquez Barragan, 39, as a top member of La Linea gang, the enforcement arm of the Juarez cartel, saying he received orders directly from cartel boss Vicente Carrillo Fuentes.
Vazquez Barragan allegedly organized payments, moved drugs and oversaw a system of safe houses in and around Ciudad Juarez.
Police said he held the same rank as fugitive gang leader Juan Pablo Ledezma, though Vazquez Barragan is not named on reward or most-wanted lists published by the Attorney General's Office, as Ledezma is.
La Linea has been blamed for a car bomb that killed three people July 15 in Ciudad Juarez and for two separate shootings March 13 that killed a U.S. consular employee and two other people connected to the consulate.
Police did not say when they caught Vazquez Barragan, but he was allegedly in possession of about a half-kilogram (pound) of cocaine and two guns.
His arrest led to a raid on a safe house where authorities detained four suspects and freed a kidnap victim.
Also Sunday, the Attorney General's Office said soldiers on patrol in Ciudad Madero in the border state of Tamaulipas seized an arsenal of about three dozen guns, 17 grenades and thousands of bullets in a house.
Elsewhere in Tamaulipas, police and prosecutors raided a lot full of truck-pulled tankers in the border city of Reynosa and seized two loaded with oil of a type sometimes stolen from the pipelines of the state-owned Petroleos Mexicanos. More than a dozen other tankers and freight containers were also seized.
Mexican drug cartels have allegedly become involved in increasingly sophisticated thefts of fuel and oil from Mexico's pipelines.
In the Pacific coast state of Guerrero, authorities reported Sunday they had found the bullet-ridden bodies of six men dumped in various locations, including three in or around the resort of Acapulco. Two of the dead men were identified as people kidnapped earlier in the month.