An Afghan official says a gunman loyal to a local warlord has opened fire inside a mosque in the northern Takhar province, killing four worshippers and wounding as many as 40 people.

Provincial police chief Gen. Faqir Mohammad Jawzjan says the attacker belongs to a militia loyal to local warlord Bashir Khan.

He says the warlord allegedly had a dispute with the mosque cleric, Maulvi Mafuz, who was the gunman's target in Friday's attack.

Mafuz was not hurt in the assault.

The cause of the dispute wasn't immediately clear but dozens of warlords who returned to positions of power after the collapse of the Taliban are protected by heavily armed local militias, who have resorted to gunbattles to settle disputes.