TRIPOLI (Reuters) - The number of people killed in an explosion and in clashes between militiamen and locals in a town east of Tripoli has risen to 40, an official said on Wednesday.

Al-Sharif Ahmad Jaddallah, a spokesman for the municipal council in Garabulli, said at least 25 people had been wounded and victims' remains were still being gathered.

Garabulli officials say fighting erupted after a dispute on Monday between a local shopkeeper and a member of a militia who was refusing to pay for goods. After the shopkeeper shot the militiaman in the leg, other militia members returned to loot the shop and burned down several houses, Jaddallah said.

"Yesterday morning, armed locals went to the places where the members of this armed group were staying but they were shot and clashes erupted," he said.

Locals then entered a house used by the militia for illegal activities including migrant trafficking.

"An ammunition store exploded when the locals were inside the house and a great number of people were killed," Jaddallah said.

Pictures from the scene showed a large crater and the aftermath of what looked like a huge explosion.

A second Garabulli official initially put the death toll at at least 20.

Militias and other armed groups have proliferated in Libya since the uprising that toppled Muammar Gaddafi five years ago, and they have largely acted with impunity in the political chaos that followed.

Libya's U.N.-backed unity government, based in Tripoli and which is tasked with uniting the country's political and armed factions, called for calm and restraint in the wake of the incident.

It said Garabulli, located around 50 km (30 miles) from the capital, would be secured by regular police and army forces in the coming days and promising an investigation.

(Reporting by Hani Amara and Ahmed Elumami; Writing by Aidan Lewis; editing by John Stonestreet)