The attack in the town of Maymana, capital of northern Faryab province, came as people were gathering at the mosque to celebrate the Eid al-Adha holiday, said a spokesman for the governor's office.
Top provincial officials, including the governor and the police chief, were inside the building when the bomber set off his explosives outside, where a large crowd had gathered, Mr Didar said. The officials were not hurt but the casualties included police officers and soldiers.
"It was a massacre. "There was blood and dead bodies everywhere," said Khaled, a doctor who was in the mosque at the time and who, like many Afghans, uses only one name. The attack came as Afghan president Hamid Karzai urged Taliban insurgents "to stop killing other Afghans". In his Eid al-Adha message, Mr Karzai called on the insurgents to "stop the destruction of our mosques, hospitals and schools".