The Ministry of Defense (MoD) said the incident has taken place recently in a remote part of the restive Andar district.
A statement by MoD said the militants were busy manufacturing Improvised Explosive Device (IED) in a house belonging to an individual identified as Abdullah when the incident took place.
The statement further added that the house is located in Kansif area of Andar district and the militants were looking to place the IEDs on a roadside when it went off, leaving five of them dead.
The anti-government armed militant groups including the Taliban insurgents have not commented regarding the incident so far.
The Taliban insurgents frequently use IEDs as the weapon of their choice to target the security forces and government officials but in majority of such incidents the ordinary civilians are targeted.
The United Nations Assistance Mission in Afghanistan (UANAMA) released its latest civilian casualties report last month, covering a period of three months since the start of 2017.
According to the report, the Anti-Government Elements caused 62 per cent of civilian casualties – 1,353 civilian casualties (447 dead and 906 injured), reflecting a five per cent increase compared to the same period in 2016.
The UN mission also added it recorded a 12 per cent increase in civilian casualties caused by pressure-plate improvised explosive devices – 218 civilian casualties (86 dead and 132 injured).