Officials said another 50 people were wounded in the blast at a gate leading away from the mosque in Maymana, the capital of Faryab province, following prayers to mark the beginning of the Muslim holiday Eid al-Adha, CNN reported.
Interior Ministry spokesman Sediq Seddiqi said the number of casualties likely would rise, considering the timing and size of the explosion.
No one claimed responsibility for the attack.
Security had been tight around the mosque, raising questions about how the suicide bomber slipped past at least four security checkpoints, the BBC said. One official said the attacker was wearing a police uniform.
The bomber attacked as Afghan President Hamid Karzai urged Taliban militants to stop "killing their people and destroying their mosques, hospitals and schools" and join the peace process.
"They can run for any position they want," Karzai said in an Eid al-Adha message. "If they want to join the government they are welcome."