Three gunmen were arrested.
The lengthy firefight erupted in the town of Tanhuato, Michoacan state, when a joint force of federal and state security forces encountered the gunmen in the course of an investigation, Mexican National Security Commissioner Monte Alejandro Rubido said at a news conference.
The gunmen belonged to a criminal organization operating in the neighboring state of Jalisco, Rubido said, though he didn't name the group.
The commissioner's description of the gunmen contradicts earlier reports that described them as "armed civilians." At least two news agencies, Reuters and AFP, reported that the confrontation was between security forces and civilians. They cited unnamed Mexican officials.
The governor or Michoacan, Salvador Jara, said in television interview that it is "very likely" that the shootout involved the Jalisco New Generation drug cartel.
Rubido told reporters that the confrontation was the result of an investigation that began the previous day. The investigation began Thursday after a property located in Tanhuato was taken over by a group of armed men.
On Friday, Rubido said, as the joint security forces drove toward the property in question, they came across a vehicle with armed men who started firing when they saw the officers.
A chase ensued where the security forces followed the gunmen into the property that had allegedly been invaded the day before, Rubido said.
According to the commissioner, at the property -- which he described as a 275-acre stretch of land with a main residence, a warehouse, and agricultural buildings -- additional gunmen entered the fray with "intensity."
Backup to aid the security officers arrived, including a federal police helicopter, at which point the gunmen spread throughout the property, Rubido said.
The confrontation stretched for hours because of the size of the property, Rubido said. There were at least three standoffs in different parts of the property, he said.
This was a slightly different version than what the mayor of Tanhuato said in an earlier interview. According to the mayor, there were two different shootouts in different locations.
The death toll was 42 gunmen and one federal police officer, who was shot while providing aid to an injured colleague, Rubido said.
The three gunmen who were arrested have been turned over to state prosecutors, he said.
In addition, the security forces seized eight vehicles, six were inside the warehouse and were burned when the structure caught on fire, the commissioner said.
A photo of the burned-out vehicles had been shared earlier on Twitter by a group of citizens who monitor violence in Michoacan.
Authorities also seized 36 long arms, two small arms, one grenade launcher and an undetermined number of ammunition, Rubido said.