Enraged villagers in a small town in central Mexico burned alive two men whom they confused with alleged child abductors, local authorities said on Thursday.

The men, 21 and 53, had been detained at the police station in the town of San Vicente Boqueron in the state of Puebla. A crowd pulled them from their cell, beat them and set them on fire on Wednesday, the state government said in a statement.

"Nearly 150 angered residents broke the door (...) taking out the two individuals," the statement said.

The state prosecutor's office discarded accusations the victims had committed any crime and said authorities had opened a homicide investigation of their deaths.

Images on social media showed the moment a furious crowd doused the men in gasoline and set them alight.

Local media quoted relatives of the men who said they were farm workers who had come to the town to buy supplies.

Mexico occasionally sees such killings. Rising criminal violence and growing frustration with ineffective police forces have been blamed for fueling such attacks.