Media playback is unsupported on your device Media caption The BBC's Bilal Sarwary: ''A number of those injured are in very critical condition''

A suicide bomber targeted worshippers who had gathered at a mosque in north Afghanistan for prayers to mark Eid al-Adha, killing at least 41 people.

More than 50 people were wounded in the attack, which happened as people were leaving the Eid Gah mosque in Maymana, capital of Faryab province.

Senior provincial government and police officials attended the prayers, but appeared to escape serious injury.

The victims were mainly police officers and civilians.

Analysis This attack in Maymana, the provincial capital of Faryab, exposes a number of serious concerns about the security situation there. There is a widespread perception that Faryab is a very peaceful province, but recent developments are telling. There have been a number of assassinations of tribal elders recently in Maymana. Nato forces have also conducted frequent night raids targeting the Taliban and the Islamic Movement of Uzbekistan militant group (IMU). The groups work in concert in Faryab and analysts believe they are behind this latest attack. The province's security elite was gathered in the mosque - they appear to have been the target of this blast. It is an indication that the militants do not intend to back down; Faryab is an important recruiting ground for the IMU and the Taliban are willing to help them as they try to expand their influence in the north.

Officials said that 14 civilians and six children were among the dead.

"We had just finished Eid al-Adha prayers and we were congratulating and hugging each other," deputy provincial governor Abdul Satar Barez told the AFP news agency.

"Suddenly a big explosion took place and the area was full of dust and smoke and body parts of police and civilians were all over the place. It was a very powerful explosion."

One survivor told the BBC that the attacker had used potent explosives and ball bearings inside his suicide jacket to cause maximum casualties.

Mr Barez said senior police and government officials had been the target, but were inside the mosque at the time so escaped the force of the blast.

Shafi Bekoghlu, a BBC Uzbek reporter based in Maymana, said he had been due to go to the mosque but was running late so went to a different mosque for Eid prayers.

"Just as I got home, I heard a very loud explosion. I rushed to the hospital and saw lots of cars, police cars and ambulances - carrying bodies in," he said, adding that police fired warning shots into the air to prevent people entering the hospital.

"I went back to the hospital a couple of hours later and saw the bodies of policemen lined up."

Doctors told the BBC that a number of the injured were in a critical condition.

Image caption Many of the bodies lined up at the hospital were police officers, witnesses said

One prominent tribal elder who survived the blast said the attacker was wearing police uniform and was not searched by members of the security forces, the BBC's Bilal Sarwary reports.

He managed to breach several layers of security, 50m from the provincial governor's office.

Intelligence reports prior to the attack had suggested insurgents wanted to target the Eid Gah mosque, in the heart of Maymana, our correspondent adds.

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, there have been a spate of assassinations in Maymana in recent days, our correspondent says.

A senior former Taliban commander, who had defected to the government side, was killed along with his son, as well as a number of very prominent tribal elders seen to be giving crucial support to the government.

Friday's attack came as Afghan President Hamid Karzai urged the Taliban 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... if they want to join the government they are welcome," Mr Karzai said of the insurgents in his Eid al-Adha message.