Karim Yorish, a spokesman for provincial police, said that that three others were wounded in the attack which happened during Maghrib prayer in Bibi Ayena area of the provincial capital, Maimana.
The official said that the attackers faced security forces encounter at a checkpoint while they were fleeing, as a result of which two were wounded.
He blamed the Taliban for the attack. The group has yet to make comment.
Meanwhile, a security source said that four people were killed and five others were wounded in the mosque shooting.
According to the source, the deaths included a local police commander, identified as Abdul Sattar, his brother and son.