More than 40 people were wounded in the attack at the front of the mosque in Maymana, capital of Faryab province.
The provincial governor and police chief were said to be among those attending the prayers to mark the Eid al-Adha holidays, but they reportedly escaped without serious injury.
Civilians and police officers were among the dead, officials said.
Eye witnesses and officials said the suicide attacker approached the mosque and detonated his suicide vest after the Eid prayers had finished.
It is not clear now the attacker managed to get past at least four security checkpoints to target the mosque.
Deputy provincial governor Abdul Satar Barez told the AFP news agency that the attacker himself was wearing a police uniform.
Attacks in northern Afghanistan are far less common than in the south and east, and Faryab province has been considered to be relatively peaceful.
However at least 10 people were killed in an incident in April 2012 when a suicide bomber on a motorbike targeted a meeting of officials near the main vegetable market in Maymana.
Image source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…